Copy link to clipboard
Copied
Can anyone help? I want to call on a button instance that lives two levels up in a movie clip. So, the mc lives here:
Scene 1 > startMc > navMC
(the navMC contains all the buttons)
I thought "page1_btn.child.child.addEventListener(MouseEvent.CLICK, page1content);" would work but doesn't seem to do it.
-----------------
The code on main timeline is:
function removeF() {
removeChild(myLoader);
}
var myLoader:Loader=new Loader ();
page1_btn.addEventListener(MouseEvent.CLICK, page1content);
function page1content(myevent:MouseEvent):void {
var myURL:URLRequest=new URLRequest("page1.swf");
myLoader.load(myURL);
addChild(myLoader);
}
Copy link to clipboard
Copied
page1_btn on the main timeline already has that listener defined.
do you have a different page1_btn on the nested timeline? if yes, try:
page1_btn.addEventListener(MouseEvent.CLICK, parent.parent.page1content);
Copy link to clipboard
Copied
Hi. No other page1_btn. The goal is to have the page1_btn call the external swf.
The problem is the navigation (and instance of page1_btn) lives 2 mcs deep. So, while the above code works if the page1_btn instance is on the mainstage, it doesn't work when the page1_btn instance is embedded in two movie clips.
Copy link to clipboard
Copied
If that button is two mc's deep, then to code it from the main timeline you need to target it thru those two mc's to assign the event listeners, so you'll need to name the container mcs...
mc1Name.mc2Name.page1_btn.addEventListener(MouseEvent.CLICK, page1content);
Otherwise, use what kGlad suggested if you want to assign the listener in the button's distant timeline
Copy link to clipboard
Copied
well that would make total sense. So I tried it. Now I get an error:
"Cannot access a property or method of a null object reference at project_fla:MainTimeLine/frame"
Copy link to clipboard
Copied
If you select the option to permit debugging in the Flash Publish Settings, you can probably get a little more info in the error message pointing at the offending line of code. In order for buttons to work with event listeners that are assigned for them, the buttons need to be in the presence of that code when it executes. So if your buttons happen to live a few frames down into the movieclip they reside in, they are not present for the event listener when it is being assigned--in that case you would have to move the listener assignment to where the button exists. A similar situation exists if you transition the button into place.
There are other possible causes, but it's a short list, which includes making sure the instance names are assigned and in agreement.
Copy link to clipboard
Copied
Thank you for answering that question. I often wondered about the buttons being "in the presence" of the actionscript. This would basically mean that the AS needs to be on the same timeline as the button.
So, any movie jumping would have to be done by the function of the button.