Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with targeting a loaded menu item (from a swf file)

Status
Not open for further replies.

jbezzina

MIS
May 4, 2004
46
MT
I have loaded a menu in _level20 (menu.swf) and I am trying to target the buttons on this menu. Can you please explain why the following is not working (it seems like I'm not targeting the button correctly)
Code:
_level20.myButton1.onRelease = function() {
	_level10.gotoAndPlay(12);
}

Yet, When I move the menu on the main timeline (for testing since this cannot be done in the real thing) all works fine:
Code:
this.myButton1.onRelease = function() {
	_level10.gotoAndPlay(12);
}

THANKS !!
 
Could be that you're setting the code before the menu has loaded in - if your loadMovie command is after the button setup the button's actions will get overwritten.

Hard to say without seeing the source files though.
 
The buttons must exist on stage before you can assign them function handlers. Thus your movie on level 20 must be fully preloaded before you do so... And certainely not on the same frame's or button's actionscript as the loading of the movie itself on level 20.
 
Thanks for the advice oldnewbie and wangbar but all failed.

I simplified things and instead on loading the menu, I included this button into another movie which was preloaded. This also failed to get the bottons working. I think I have figured out another way to get what I need, but I wish to solve this one. Can you please try it out yourself and see if you get the same result? Here is what to do (Quite simple)

preload a movie into _level20 - This should contain a button (myButton1)

preload another movie into _level10 - This should contain a simple animation with a stop() action on frame 1

in the main timeline:

_level20.myButton1.onRelease = function() {
_level10.gotoAndPlay(2);
}

I look forward to your suggestions

Thanks.
 
Hi, it's me again. I give up. I though I had a way out of this problem but this also failed.

I have prepared an example for you to see. I have included .fla and .swf files in a (100% virus free :) zip file located here:


(run the main_page.htm or .swf file)

Can you PLEASE !! take a look.

Thanks.
 
Here you go. You just needed to add a listener so the assignment of the function does not occur until after the "menu" clip has loaded. That is what Wangbar and OldNewbie were trying to say.

In your main_page.fla this should be your script:

Code:
var myMCL:Object = new MovieClipLoader();
myMCL.loadClip("menu.swf", 10);
myMCL.loadClip("animation.swf", 20);

myListener = new Object()
myListener.onLoadInit = function (target_mc){
	_level10.AnimatonButton2.onRelease = function(){
		_level20.gotoAndPlay(2);
	}
}
myMCL.addListener(myListener);

this.AnimatonButton1.onRelease = function(){
	_level20.gotoAndPlay(2);
}

Then you should be good to go!

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
Here you go. You just needed to add a listener so the assignment of the function does not occur until after the "menu" clip has loaded. That is what Wangbar and OldNewbie were trying to say.

In your main_page.fla this should be your script:

Code:
var myMCL:Object = new MovieClipLoader();
myMCL.loadClip("menu.swf", 10);
myMCL.loadClip("animation.swf", 20);

myListener = new Object();
myListener.onLoadInit = function (target_mc){
	_level10.AnimatonButton2.onRelease = function(){
		_level20.gotoAndPlay(2);
	}
}
myMCL.addListener(myListener);

this.AnimatonButton1.onRelease = function(){
	_level20.gotoAndPlay(2);
}

Then you should be good to go!

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
Hi. Thanks it worked at last, BUT...

I still cannot understand what the listener is for. I tried to read about it but all I found is how to use it. Why it is used and the way the code is structured is never explained.

Can someone please explain the addListener to me?

Thanks.
 
The listener is a bit of code that monitors the status of a command that you have given. In this case you have used MovieClipLoader.load so your options for listeners are onLoadComplete, onLoadError, onLoadInit, onLoadProgress, and onLoadStart. This is fairly well documented in the help system under MovieClipLoader class.

The reason you need to use it is just the problem you were having. You were assigning code to a button that had not completed loading yet. It's kind of like you were trying to drive a car that you won't have until tomorrow.

The listener OnLoadInit tells it to wait until it has executed the first frame of the movie clip you have loaded before it fires the OnLoadInit function.

I hope that makes it a little clearer for you.

Wow JT that almost looked like you knew what you were doing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top