PDA

View Full Version : AS3 movie clip looping animation


geeem
01-01-2010, 06:13 PM
Hi

I hope someone can help...

I have a mc which plays a frame-by-frame animation over several frames and results in the chraracter walking a few steps (left to right). If this is placed just off-stage (stage-left) the character appears to walk on when the movie is tested.
Now I want to script the movie (AS3) so he appears to walk all the way across the stage and disappear (stage-right).
I have achieved this is a very tedious way, by duplicating frames in the mc, but I would like to do it in script.
I have got partial success with the code below. The first mc (instance name, mach_mc) has been physically placed stage-left. He does his walk, then the code adds a duplicate from the Lib, just where the first walk ends. This works fine, as he appears to walk that bit further across the stage. Trouble is, when I now try to repeat the main section of code, to add another duplicate, it all goes wrong.
Here is the code I have so far...

var myTimer:Timer=new Timer(20);
myTimer.addEventListener(TimerEvent.TIMER,loadmc);
myTimer.start();
function loadmc(event:Event) {
if (mach_mc.currentFrame==mach_mc.totalFrames) {
var mach1_mc:machWalk = new machWalk();
mach1_mc.x=140;
mach1_mc.y=230;
addChild(mach1_mc);
mach_mc.visible=false
myTimer.stop();
}
}

I am now trying to get the desired result with an array and a loop, but have hit problems.

What is the simplest way of getting this to work?

Thank you very much in advance for any help.

yoshiness
01-01-2010, 08:59 PM
The easiest way I can tell you how to do this is to not use ActionScript.

Instead, have all the walking frames walk in place, and on the main timeline, just tween the movie clip across the stage.

Or if you're just using 1 frame on the main timeline, convert everything inside the walking movie clip into another movie clip. Outside the original movie clip, just tween that across the stage.

Sounds confusing, I know. I can post an example if needed.

geeem
01-01-2010, 10:09 PM
Thanks for taking the time to reply.
I have succeeded in getting the result I want by just copying/pasting the frame-by-frame animation. And I'm OK about tweening to get the result as well.
But as I'm exploring AS3, I was keen to see how it could be done in code and frustrated that I'd got part way there, but couldn't finish it.
So I'd still be very grateful if anyone can suggest the easiest coding solution.