Monday, December 28, 2009

How do I make an object move it's self in actionscript/flash?

I have a graphic, converted to a symbol. I am sure there is a way to simply move the object along a vector, but I am not at all familiar with action script. If someone can point me in the direction of how to execute a function each time a frame ticks by it would help me out.How do I make an object move it's self in actionscript/flash?
kk, on macromedia flash there are a few ways 2 do it. after u ave converted the object to a sybmol if u just want it to go in a straight line all u do is look at the timeline at right click somewhere around 30 and select insert keyframe. so on 0 put the object where u want it to start and on 30 where u want it 2 end. on 15 right click and select insert motion tween. control%26gt;play. if u want it to go somewhere else after that, go right click somewhere around 60 and select motion tween. On 60 select whee u want it to end. somewhere around 45 right click and selct insert motion tween. if u want two put in another shape moving in other directions. hide the layer u have already made (right click where it says layer one, hide layer) and right click and make a new layer (right click near layer 1, add new layer). draw shape%26gt;convert to symbol%26gt;repeat the previous steps. if u want to go even more complicated and turn one shape into another, do the same steps but make the last frame, a different shape from what u started on. at the bottom of the screen click properties. select shape tween (this will only work if u have clicked the timeline). control%26gt;play. should work. if u want to export the file click file%26gt;export%26gt;export as movie. save file, click ok. go into ur documents where it has been saved drag it onto a blank internet page and voila u wiill see it.





hope i helped and that its not 2 hard to undersand





if ur struggling just send me a message and i'll help u.How do I make an object move it's self in actionscript/flash?
Here is your code - just copy and paste it to first frame of your flash document (CS3)


use arrow keys to move the object


:-)





////////////////////////////////////


var UrShape:Shape = new Shape();


addChild(UrShape);


UrShape.x = 100;


UrShape.y = 100;


UrShape. graphics. lineStyle (3, 0x00CC99);


UrShape. graphics. beginFill (0x000000, 1);


UrShape. graphics. drawRect (0, 0, 100,100);


UrShape. graphics. endFill();


stage. addEventListener (KeyboardEvent.KEY_DOWN, MoveRectangle);





function MoveRectangle (keyEvent: KeyboardEvent): void {


switch (keyEvent.keyCode) {


case 37 ://left arrow


UrShape.x--;


break;


case 38 ://up arrow


UrShape.y--;


break;


case 39 ://right arrow


UrShape.x++;


break;


case 40 ://down arrow


UrShape.y++;


break;


default :


break;


}


}


/////////////////////////////////////








Anil


anilkumarnd@gmail.com

No comments:

Post a Comment