Skip to main content
Known Participant
December 30, 2008
Question

target swifts button

  • December 30, 2008
  • 6 replies
  • 586 views
having difficulty targeting a loaded swift and it's button
stage2.swf has no script just a button with a library and instance name "obj1" and is exported for actionscript

var stage2:URLRequest = new URLRequest ("stage2.swf");
var stage2Loader: Loader = new Loader();

stage2Loader.load(stage2);
addChild(stage2Loader);

stage2.obj1.addEventListener(MouseEvent.CLICK, myClick);

function myClick(evt:MouseEvent):void
{
gotoAndStop(10);
}
This topic has been closed for replies.

6 replies

clbeech
Inspiring
December 30, 2008
bingo - nice work Ned :)

"Hey CL!... not quite 23 seconds, but you always seem a step faster than me."

hey Ned - you saw that eh LOL!!! ;)
Known Participant
December 30, 2008
thank you very much NedWebs that works great
Known Participant
December 30, 2008
sorry I'm so tierd I forgot to say thanks for the replys in my last post
thanks for the replies I'm going to bed will try on fresh mind tommorrow
good night sincerely newwave
ps here is my latest try

var loader:Loader = new Loader();
var stage2:URLRequest = new URLRequest ("stage2.swf");
loader.load(stage2);
addChild(loader);

Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
function loadComplete():LoaderInfo {
loader.stage2.obj1.contentLoaderInfo.addEventListener(MouseEvent.CLICK, myClick);
}
Ned Murphy
Legend
December 30, 2008
I'm taking a rough stab at this... per your last posting...

var loader:Loader = new Loader();
var stage2:URLRequest = new URLRequest ("stage2.swf");

addChild(loader);

function loadComplete(e:Event):void {
e.target.content.obj1.addEventListener(MouseEvent.CLICK, myClick);
}

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);

loader.load(stage2);

If that doesn't work, I'll try to get back with better attention to what I offered... or someone else will.
Known Participant
December 30, 2008
it's an external swift with one library button allready placed on stage and given instance name obj1

never played with loaderinfo
I tried these am I on the right track? allthough I get errors

function getLoaderInfoByDefinition(object:Object):LoaderInfo{
stage2.obj1.addEventListener(MouseEvent.CLICK, myClick);
}

and this
loader.stage2.obj1.contentLoaderInfo.addEventListener(MouseEvent.CLICK, myClick);
Ned Murphy
Legend
December 30, 2008
You probably need to have a listener for the Loader so that you aren't trying to assign the obj1 listener before it's arrived.

I'm not sure if the button is loaded from the library between your saying that the swf has no script and the button is exported for actionscript, but if it is, you may need a tad more time for that as well? (I'm not sure on that aspect)

Hey CL!... not quite 23 seconds, but you always seem a step faster than me.
clbeech
Inspiring
December 30, 2008
you'll need to use a LoaderInfo object and the init handler here and place the addEventListener within the handler. the reason is that one cannot apply the handler to an object that does not yet exist - it must be loaded and instantiated on the timeline before you can do so.