Follow Me On

 

https://www.youtube.com/user/mrsumitranaware

https://www.instagram.com/sumit.ranaware/

https://sumalno.wordpress.com/

https://www.facebook.com/suma.lno/

Advertisements

Controlling Movie Clip by Buttons AS3

 

Make a box, the select it and press F8 make it a button and press ok.. Give it a instance name “mc”.

 

Create a button and name instance as “btn_right”.


Press on the first frame in the timeline and press F9. In the Action panel copy the following code.

 

btn_right.addEventListener(MouseEvent.CLICK, move_right);

 

function move_right (e:Event){

mc.x += 5;

 

}

 

this will make make your Movie Clip move to right.

Remember “+” sign keep adding the value to x.

 

to understand the x and y, Just remember as a photographic memory x stands for horizontal and y stands for vertical.

 

 

 

 

 

 

Now to move Movie Clip in all directions UP, DOWN, LEFT and RIGHT. We need to make more buttons name the instances as “btn_down” ,“btn_up” and “btn_left”.

 

To move left :

 

btn_right.addEventListener(MouseEvent.CLICK, move_left);

 

function move_left (e:Event){

mc.x -= 5;

 

}

 

To move up :

 

btn_right.addEventListener(MouseEvent.CLICK, move_up);

 

function move_up (e:Event){

mc.y -= 5;

 

}

 

To move down :

 

btn_right.addEventListener(MouseEvent.CLICK, move_down);

 

function move_down (e:Event){

mc.y += 5;

 

}

 

}

 

this will make make your Movie Clip move to right.

Remember “+” sign keep adding the value to x.

 

to understand the x and y, Just remember as a photographic memory x stands for horizontal and y stands for vertical.

 

 

 

 

 

 

Now to move Movie Clip in all directions UP, DOWN, LEFT and RIGHT. We need to make more buttons name the instances as “btn_down” ,“btn_up” and “btn_left”.

 

To move left :

 

btn_right.addEventListener(MouseEvent.CLICK, move_left);

 

function move_left (e:Event){

mc.x -= 5;

 

}

 

To move up :

 

btn_right.addEventListener(MouseEvent.CLICK, move_up);

 

function move_up (e:Event){

mc.y -= 5;

 

}

 

To move down :

 

btn_right.addEventListener(MouseEvent.CLICK, move_down);

 

function move_down (e:Event){

mc.y += 5;

 

}