PDA

View Full Version : deadline today swf with mutliple buttons to load child swfs that I can't get to work



fherrmann
March 26th, 2009, 08:17 AM
First off I am really new to the whole actionscript 3 arena and am having a lot of trouble getting things to work. And I have a deadline of today to have this finished....gulp!!!

here is the scenario..I have a picture on the stage that has multiple items that have hotspots/links over them that should open a child swf on top of the background and show details about the items. I found this code in someone's post and I am trying to modify it so that works for multiple buttons ...it currently works for a button loading a single swf. The name of the instance name of the buttons is the same as the name of the swf file that they load so I thought I could do something that when the button is clicked it would pass the name of the button into the URLRequest but I can't figure it out. Here is the code I am using.

////////////////////////////////// code from the actions layer
var bioloader:Loader;
var biocontainer:MovieClip;


one.addEventListener(MouseEvent.CLICK, biowindow);
two.addEventListener(MouseEvent.CLICK, biowindow);
three.addEventListener(MouseEvent.CLICK, biowindow);
four.addEventListener(MouseEvent.CLICK, biowindow);

function biowindow(e:MouseEvent): void {

// I am guessing I should be adding something here like eventname.biowindow + ".swf"
var biorequest:URLRequest = new URLRequest("one.swf");

bioloader = new Loader();
bioloader.load(biorequest);


biocontainer = new MovieClip();
//RS: add to the timeline, not the stage
this.addChild(biocontainer);
biocontainer.addChild(bioloader);

// positions bioloader on stage
biocontainer.x = 0;
biocontainer.y = 0;


trace(biocontainer.stage);
trace(biocontainer.root);
}



var receiver:LocalConnection = new LocalConnection();
receiver.connect("lcClient");


receiver.client = this;
function closeBio(): void {

trace("lc called successfully");

biocontainer.removeChild(bioloader);

}

m90
March 26th, 2009, 08:27 AM
If you want it quick (I think you do :) ) the easiest thing would be to check for the currentTraget and then specify your URL accordingly like:



var biorequest:URLRequest;

if (e.currentTarget == one){
biorequest = new URLRequest("one.swf");
} else if (e.currentTarget == two){
biorequest = new URLRequest("two.swf");
} else if (e.currentTarget == three){
biorequest = new URLRequest("three.swf");
} else if (e.currentTarget == four){
biorequest = new URLRequest("four.swf");
}



A better solution yet might be to create a custom class for your buttons that contain the URL they are linking to. Or you could just use the name property of your MCs if you aren't using it otherwise.

Hope it helps!

pixelsguy
March 26th, 2009, 12:48 PM
what is the local connection stuff for?

also, instead of using if(a=1){}else if(a=2){}else if(a=3){} you can use a switch-

switch(a){
case 1:
actions;
break;
case 2:
actions;
break;
case 3:
actions;
break;
}

a switch runs through its cases, from top to bottom, looking for an equality to the term in the switch call.

or you can just use

String(evt.currentTarget.name)+".swf", where evt is your mouse event of the button click function.