PDA

View Full Version : target a button inside a mc in order to trigger a sw



michaelafoley
February 10th, 2010, 02:44 PM
Hello everyone,
Trying to target a button inside a mc in order to trigger a swf. The swf has the same name as the listener in order to repeat the function with multiple swfs. my problem is, i'm getting an error of an Access of undefined property with my mc


I geting an error:"

1120: Access of undefined property nav_btns.



var Xpos:Number = 461;
var Ypos:Number = 294;
var swf:MovieClip;
var loader:Loader = new Loader();

var defaultSWF:URLRequest = new URLRequest("swfs/nav_btns.contact_btn.swf");

loader.load(defaultSWF);
loader.x = Xpos;
loader.y = Ypos;
addChild(loader);

function btnClick(event:MouseEvent):void {

removeChild(loader);
var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.target.name + ".swf");
loader.load(newSWFRequest);
loader.x = Xpos;
loader.y = Ypos;
addChild(loader);
}
// Btn listeners
nav_btns.contact_btn.addEventListener(MouseEvent.C LICK, btnClick);
nav_btns.service_btn.addEventListener(MouseEvent.C LICK, btnClick);

okashira
February 10th, 2010, 04:05 PM
it looks to me like you're adding the swf to the stage before it's fully loaded.
use the addChild only when you're sure that the swf is fully loaded, you can do that by adding a listener like so...

loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, fullyLoaded);
function fullyLoaded(e:Event):void{
var myLoader:Loader = Loader(e.target.loader);
addChild(myLoader);
}

or

make sure you gave your buttons names

michaelafoley
February 10th, 2010, 06:05 PM
My problem is I don't know how to call buttons that are located inside the movieclip?
nav_btns is the mc,
contact_btn is the button inside

script example:
nav_btns.contact_btn.addEventListener(MouseEvent.C LICK, btnClick);

everything is labeled correct and i still get a undefined error

michaelafoley
February 10th, 2010, 09:12 PM
Ok, but that does not help with the problem at hand. If i place the button, "contact_btn" on the main stage that plays the swf file everything woks well. I would like to place the button inside a movie clip called "nav_btns". when i direct the listener to the button in the mc i get an undefined property?

but i figured it out "use the Target" in AS3