I'm trying to make a block of AS3 code work with an older Flash movie. A movie consisting of ~4000 keyframes and having static movie clips added to main timeline periodically.
On frame no 120, a movieclip with instance name of playButtonMC
is added to stage. playButtonMC
has a button
instance named playButton
inside it. I want to assign click event handler to the button inside this movie clip from main timeline but I'm failing to get a reference to the movie clip from actions on keyframe # 121 on main timeline.
I've tried following in vain:
var myMc:MovieClip = stage.getChildByName("playButtonMC") as MovieClip;
trace(myMc);
trace(playButtonMC);
trace(root.playButtonMC);
trace(stage.playButtonMC);
// If I get a reference, I plan to do following to attach event listener.
// Please advise if its incorrect as well
myMc.playButton.addEventListener(MouseEvent.CLICK, doStuff);
function doStuff():void{
trace('called');
}
All calls to trace
result in null
.
I'm not a Flash developer in any sense but I've been handed over this small task. I know the right AS3 way of doing it must be by dynamically generating the movie clips and storing the references in variables but, at the moment, I'm only trying to make it work somehow.
EDIT
trace(stage.playButtonMC);
actually creates an error ReferenceError: Error #1069: Property playButtonMC not found on flash.display.Stage and there is no default value.