Pages

Thursday, June 21, 2012

How to find Variable type in as3

Object,Array,Number,String,MovieClip,Sprite there are basic variable type in as3.

var a1:Object=new Object();
var a2:Array=new Array();
var a3:Number=new Number();
var a4:String=new String();
var a5:MovieClip=new MovieClip();
var a6:Sprite=new Sprite();
var container:Array=new Array(a1,a2,a3,a4,a5,a6);

here which variable is a Object from container array?

for(var i:int=0;i<container.length;i++)
{
    if(typeof(container[i])=="object")
    trace("this one is object type variable: "+container[i]);
}

...CHeeRS...


Send and Get data from JavaScript in AS3

How to Connect JavaScript in as3?

External Interface:-
      The ExternalInterface class is an application programming interface that enables straightforward communication between ActionScript and the SWF container- for example, an HTML page with JavaScript or a desktop application that uses Flash player to display a SWF file.

Using the ExternalInterface class, you can call an ActionScript function in the Flash runtime, using JavaScript in the HTML page. The ActionScript function can return a value, and JavaScript receives it immediately as the return value of the call.


import flash.external.ExternalInterface;

// calling a javascript function from as3 (with optional parameters)
if(ExternalInterface.available)
ExternalInterface.call("javascriptFunction",param1,param2);
//implementing a javascript callback in as3 (flashFunction is called when Javascript calls javascriptFuntion)
if(ExternalInterface.available)
ExternalInterface.addCallback("javascriptFunction",flashFunction);

Example:

JavaScript code:-

<script>
function jsAdd(value1,value2)
{
       return ('ans:'+value1+value2);
}
</script>

as3 code:-

import flash.external.ExternalInterface;


var output:String=ExternalInterface.call("jsAdd",10,15);
ExternalInterface.addCallback("jsAdd",callJs);


function callJs():void
{
     trace("successfully called js method");
}

...CHeeRS..