Action to Object in Array AS3 – Tutorial

 

 

make a movie clip,  drag it from libray. We need at least 4  copies of same movie clip.Now rename each as mc_0, mc_1,mc_2, mc_3.

in action script panel past this code.

var mc:Array=new Array (mc_0, mc_1,mc_2, mc_3);
trace (mc.length);
==========================================
//Output
4
==========================================

Now how we have 4 movie clips , how are we going to give the action to all ?We nee to create a loop to give actions to all mc”s in array.
in action script panel past this code.

for (var i:int; i<mc.length; i++){

trace(“ok”);
}
==========================================

output should be as :
ok
ok
ok
ok
==========================================
add this above  trace(“ok”)

mc[i].addEventListener(Event.ENTER_FRAME, move);

Now we have given action to all the objects. Now we need to create and action , what action to be performed by the movie clips ? paste this code after “for”.

function move(e:Event){

mc[i].rotation ++;

}
Your last code should look like this :

==========================================
var mc:Array=new Array (mc_0, mc_1,mc_2, mc_3);
trace (mc.length);

for (var i:int; i<mc.length; i++){
mc[i].addEventListener(Event.ENTER_FRAME, move);
trace(“ok”);
}

function move(e:Event){

mc[i].rotation ++;

}

==========================================

This will make your all objects rotate around itself. If this works.

try following
mc[i].alpha = 0.2;
mc[i].x= 5;
mc[i].y= 5;

==========================================
remember  mc[i].x += 5;   the plus sign keeps om adding the value to object. Means mc will keep moving in x direction till it goes out of the stage.

these are many things we can do, we shall proceed to advance level in next tutotials.
Thank you.

Array in AS3 (Basic)

array is like a file or like a book in which we can store information about names or numbers.

var numbers:Array=new Array (1,2,3,4,5,6,7,8,9,0);
var god_names:Array=new Array (krishna, shiva, buddha, christ);
var countries:Array=new Array (india, nepal, china, thailand);

trace (numbers);
trace (god_names);
trace (countries);

Output//

1,2,3,4,5,6,7,8,9,0.
krishna, shiva, buddha, christ.
india, nepal, china, thailand.
=============================================

trace (countries.length); // this gives the number of the words stored in an Array.
Output//
4

Movie Clip Drag Tutotial AS3

 

Make a movie clip and give in an instance name “mc”.
click on the frame in the timeline and press F9.

and past the following code :

mc.addEventListener (MouseEvent.MOUSE_DOWN, start_drag);
function start_drag (e:Event){

mc.startDrag();

}

 

this will allow to drag the movie clip, now we also need to give it an action as stop drag when mouse click in disable.

mc.addEventListener (MouseEvent.MOUSE_UP, stop_drag);
function stop_drag (e:Event){

mc.stopDrag();

}

 

Hope you got it. 🙂

Music Player In Flash CS3

Music Station by Sumit Ranaware

 

Created Music Player in Flash which actually works. 🙂
Added 7 songs in playlist and its playing.
After so much of hard work, ordinary music sounds much sweeter . 🙂

Duration : 1 Day.
Software : Flash, Photoshop, notepade & Dreamwever.
Language : Action Script 3

Flash Portfolio

My Flash Portfolio
Profile Gallery

This is Gallery Page. All done in action script 3.
took me 3weeks ….got images from xml. Used scroll bar in case if I want to add more work…scroll bar will maintain..all images….its cool component…….
Tasa tar mi lahanpana pasunch hushar aahe …:P