Flash actionscript 3.0: March 2009

how to display the external "XML" file in flash AS 3.0

0

Posted by Sankar.G | Posted in | Posted on 11:29 PM

var externalXML:XML=new XML;
var loader:URLLoader=new URLLoader();
var urlrequest:URLRequest=new URLRequest("Data.xml");
loader.load(urlrequest);
loader.addEventListener(Event.COMPLETE,one);
var rows:Number;
var array:Array=new Array();
function one(e1:Event):void
{
externalXML=new XML(loader.data);
rows=externalXML.Employee.Employee_Data.length();
for(var i:uint;i< rows;i++) { array.push({name_arr:externalXML.Employee.Employee_Data[i].@ Names,age_arr:externalXML.Employee.Employee_Data[i].@ Age,id_arr:externalXML.Employee.Employee_Data[i].@Id}); } display(); } function display():void { names.text=ages.text=ids.text=" "; for each(var arr in array) { names.appendText(arr.name_arr+"\n"); ages.appendText(arr.age_arr+"\n"); ids.appendText(arr.id_arr+"\n"); } } arr1_btn.addEventListener(MouseEvent.CLICK,two); arr2_btn.addEventListener(MouseEvent.CLICK,three); function two(e2:MouseEvent):void { array.sortOn("name_arr",array.DESCENDING); display(); } function three(e3:MouseEvent):void { array.sortOn("age_arr",array.DESCENDING|array.NUMERIC); display(); } create 3 text box and name it as names,ages,ids and create 2 buttons and name it as arr1 & arr2 to arrange the values in decending order below we have XML file store the XML file near to the flash file and Name it as Data.xml < Datas>
< Employee>
< Employee_Data Names="a" Age= "10" Id= "13" />
< Employee_Data Names="g" Age= "12" Id= "523" />
< Employee_Data Names="e" Age= "55" Id= "63" />
< Employee_Data Names="w" Age= "22" Id= "403" />
< Employee_Data Names="y" Age= "24" Id= "293" />
< Employee_Data Names="q" Age= "66" Id= "883" />
< Employee_Data Names="o" Age= "97" Id= "813" />
< Employee_Data Names="z" Age= "13" Id= "723" />
< /Employee>
< /Datas>

How to get Next Highest Depth in AS 3.0

0

Posted by Sankar.G | Posted in | Posted on 11:49 AM

In AS2.0 we use getNextHighest depth but in AS3.0 we dont have that function for that we have
swapChildren()
swapChildrenAt()
getChildIndex()
setChildIndex()

by using this kind of function we want to create that

Below File is used to you

highestDepth.zip

next.swf

Timer Event in AS3.0

0

Posted by Sankar.G | Posted in | Posted on 3:59 PM

var min:Number=0;
var myTimer:Timer = new Timer(1000);
myTimer.addEventListener(TimerEvent.TIMER, myFunction);
min_txt.text=String(min);
function myFunction(event:TimerEvent):void
{
sec_txt.text=String(myTimer.currentCount);
if(myTimer.currentCount==10)
{
myTimer.stop();
myTimer.reset();
myTimer.start();
min=min+1;
min_txt.text=String(min);
}
}
myTimer.start();

Create 2 text box and Name it as sec_txt & min_txt and put this script

how to store the object X&Y values in Array using AS3.0

0

Posted by Sankar.G | Posted in | Posted on 3:51 PM

var objectArray:Array = new Array();
for (var i:uint = 0;i<
Objects.numChildren;i++)
{
var point:Point = new Point(Objects.getChildAt(i).x , Objects.getChildAt(i).y);
objectArray.push(point);
Objects.getChildAt(i).addEventListener(MouseEvent.MOUSE_DOWN, process);
}




reset_btn.addEventListener(MouseEvent.CLICK, resetAll);
function resetAll(event:MouseEvent):void
{
for(i = 0; i<
Objects.numChildren;i++)
{
Objects.getChildAt(i).x = objectArray[i].x;
Objects.getChildAt(i).y = objectArray[i].y;
}
}
put all the objects in one Movie clip and name it as Objects and write this script

getting XML Datas from XML file in AS3.0

0

Posted by Sankar.G | Posted in | Posted on 3:49 PM

var url:URLLoader=new URLLoader();
var xml:XML=new XML();
url.addEventListener(Event.COMPLETE,one);
url.load(new URLRequest("one.xml"));

function one(e:Event):void
{
xml=new XML(e.target.data);
two(xml);
}
function two(xml2:XML)
{
var list:XMLList=xml2.Book.children();
for each (var xml3:XML in list)
{
trace(xml3);
}
}

one.xml is a xml file save the xml file in same folder with this file

how to declare a global variable in AS3.0

1

Posted by Sankar.G | Posted in | Posted on 3:20 PM

create a class file and name it as Globe and put this script in class file

package
{
public class Globe
{
public static var temp:Number = 0;
}
}

And in flash AS3.0 file temp is the global variable you can use like this

Globe.temp =5;

how to add click event dynamically in As3

0

Posted by Sankar.G | Posted in | Posted on 2:43 PM

var i:Number;
for(i=0;i<=(buttonHolder.numChildren-1) ; i++)
{
buttonHolder.getChildAt(i).addEventListener(MouseEvent.CLICK, starter);
}

function starter(e:MouseEvent):void {
var ob=e.currentTarget;
trace(ob.name.substr(1));
}


select all buttons and create a movie clip and name it as buttonHolder and put this script it will work

how to put stage objects in array using flash AS 3.0

0

Posted by Sankar.G | Posted in | Posted on 10:58 AM

var a:Array=new Array();
var b:Array=new Array();
var c:Array=new Array();
var objec:Array=new Array();
var myarray:Array=new Array();
var i:Number;
var temp:Number;
for(i=0;i<
container.numChildren;i++)
{
objec.push(container.getChildAt(i));
}
for(i=0;i<
objec.length;i++)
{
temp=objec[i].name.slice(1);
myarray[temp]=objec[i];
}
for(i=0;i<
container.numChildren;i++)
{
trace(myarray[i].name);
}

Select all MovieClip which are all you want to put in array and create a new Movie Clip and

name it as container and push that container to array and name the movie clip inside the container in line like a1,a2,a3,a4....... like that and slice the array and store the last number in temp and corrosponding object in that array ......