ForumsProgramming ForumTimeline Programming ?

5 3487
Hectichermit
offline
Hectichermit
1,828 posts
Bard

Does anyone know a good example of timeline control, For example if I create a movieclip then link a class to that movieclip could I make a function in the parent class that would stop at every frame in the children of this class, or must I control only the timeline of each child after I instantiate them?

  • 5 Replies
akunu
offline
akunu
35 posts
Nomad

Ok, I'm not sure if I understand what you are asking. Do you mean like stopping the MovieClip from the main timeline?


//Create the movieclip
var mov:MyClip = new MyClip();
//This is the code that stops the movieclip.
mov.stop();
//add that **** to the stage
addChild(mov);

If not, please explain more, and i'll be happy to help.
beech
offline
beech
107 posts
Nomad

i think he's referring to the children of the Class instance - if so you use something like:

public function stopAll():void {
for( var i:int=0; i<numChildren; i++ ) {
getChildAt(i).stop();
}
}

beech
offline
beech
107 posts
Nomad

above assumes that this is a method of the Class instance - and that all children are indeed MCs

sorry for the double post (wish there was a edit)

Hectichermit
offline
Hectichermit
1,828 posts
Bard

well I figured it out why my code wasn't working :P the Movieclip in my
library wasn't linked to the correct class...anyways thanks for the help I will show ya'll my code

What is does is whenever you create an instance of MC on the stage it will stop the Timeline for that particular instance the function with the same name as the class(the constructor function, which also the same name as my movieclip but this isn't nesecssary) runs the exact same time when an instance is made. Idk I know a little about programming, still kinda new to Flash and AS3



The Movieclip Class which is linked to the Movieclip in the Library

package
{

import flash.display.*;

public class MC extends MovieClip
{

public function MC()
{
this.stop();

}
}

}


The Document Class

package
{
import flash.display.*;

public class Main extends MovieClip
{

public function Main()
{
var mcInstance: MC= new MC();
mcInstance.x = 100;
mcInstance.y = 100;
addChild(mcInstance);
}
}
}

beech
offline
beech
107 posts
Nomad

LOL - yup i was wrong there :P

quick note though: if you want to be able to contact your MC instance again from the document class (or elsewhere) you may want to move the property declaration (var) outside of the Document Class constructor - that way you store a reference to the object which you can use down the road - for instance:

package {
import flash.display.*;

public class Main extends MovieClip {

public var hero:MovieClip;

public function Main():void {
hero = new Hero();
addChild( hero );
}

public function quit():void {
removeChild( hero );
}

}
}

Showing 1-5 of 5