PDA

View Full Version : n number of MovieClips-plays topmost only



warren
May 22nd, 2009, 12:23 AM
I have 4 TextFields in a BaseClass

Text1
Text2
Text3
Text4

Each textfield has its own subclass extending BaseClass (i.e. Text1.as)

Each of the text fields in its subclass has an addEventListener tied to it so that when clicked, it plays a movie clip.

When I trace, I can mouseOver each textfield and the output is correct (mousing over Text3 outputs "Text3" in the console)


Problem: It won't play the movie clips tied to Text1-Text3: it only plays the topmost (last added) clip which is mc4.

If I comment out the addChild(mc4) movie clip in Main() , Text4Field no longer receives events, but it plays movie clip 3 when Text3 is clicked.

mouseChildren won't work here.

Any help? I'm very new to AS3

Thanks.

efos
May 22nd, 2009, 12:25 PM
What does your event listener look like?

warren
May 22nd, 2009, 10:41 PM
What does your event listener look like?


Thanks for the look at.

Each subclass constructor has the following:

Text(x).addEventListener(MouseEvent.MOUSE.CLICK, playmcx);

Where x is the respective textField # or mc# as applicable

I think this is a depth issue which I don't know how to proceed. Commenting out the addChild() in Main() plays the next clip underneath it.

efos
May 27th, 2009, 08:31 AM
Thanks for the look at.

Each subclass constructor has the following:

Text(x).addEventListener(MouseEvent.MOUSE.CLICK, playmcx);

Where x is the respective textField # or mc# as applicable

I think this is a depth issue which I don't know how to proceed. Commenting out the addChild() in Main() plays the next clip underneath it.

Sorry, long weekend.

But what does the playmcx function look like? I'm having a hard time picturing the code that would do what you're describing. Being new to AS3, I would suspect you've just gone about doing it in an unorthodox manner.

You could have one function do it all, and add the listener on the parent clip; ie:

if mcStage has text1-4 and mc1-4; then this code goes on mcStage



text1.addEventListener(MouseEvent.CLICK, clickHdlr)
text2.addEventListener(MouseEvent.CLICK, clickHdlr)
text3.addEventListener(MouseEvent.CLICK, clickHdlr)
text4.addEventListener(MouseEvent.CLICK, clickHdlr)

function clickHdlr(e:MouseEvent):void{
var sName = "mc"+e.target.name.slice(-1); //text1 would give us "mc" + "1", or "mc1"

this[sName].play(); //Gets the property or child of this called "mc1" and tells it to play

//I think the above line is a poor practice, but it's the the first method I think of.
//Alternately:

getChildByName(sName).play(); //Does the same thing
}
alternately, you could use the same class for all your text fields and write the function in that class as:



package myclasses.text
{
import flash.text.TextField;

private var sName:String;
private var pRef:MovieClip;
private var tgtMC:MovieClip;

public class MyTextField extends TextField
{
sName = "mc"+this.name.slice(-1);
pRef = MovieClip(parent)
tgtMC = MovieClip(pRef.getChildByName(sName))
this.addEventListener(MouseEvent.CLICK, clickHdlr)
}
private function clickHdlr(e:MouseEvent):void{
tgtMC.play();
}
}
Disclaimer: I am barely awake. If any of that actually compiles I want a cookie :)