Yikes, Sorry but I’m really having problems migrating to AS3 :puzzled:
A big conceptual hole I can’t seem to wrap my head around is how do you pass parameter arguments with listeners? Forget classes for right now - baby steps - I cannot even figure out the basics in calling functions on the timeline! All code on frame 1 of main.
Here’s my old style function with sample call
// Function to load items
function gearLoader(sItem,nSide):Void{
this["btn" + sItem].onRelease = function(){
mcItem.loadMovie(sItem + ".swf");
mcItem._x = nSide;
tDesc.text=lvItemDesc[sItem];
tTitle.text=lvItemTitle[sItem];
tTitle.setTextFormat(tfTitleFormat);
mcProducts._alpha=30;
}
}
//sample call
gearLoader(“goggles”, 244);
So now, in AS3, I set up my loader instance and register my button listeners.
[AS]var swfLoader:Loader = new Loader();
var sRequest:URLRequest = new URLRequest(“boots.swf”);
//add to display list
addChild(swfLoader);
//event handling - subscribe listeners
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,handleImage);
btnRod.addEventListener(MouseEvent.CLICK, gearLoader);
btnVest.addEventListener(MouseEvent.CLICK, gearLoader);
btnWadeBoots.addEventListener(MouseEvent.CLICK, gearLoader);
btnHat.addEventListener(MouseEvent.CLICK, gearLoader);
btnHelmet.addEventListener(MouseEvent.CLICK, gearLoader);
btnBoots.addEventListener(MouseEvent.CLICK, gearLoader);
btnGoggles.addEventListener(MouseEvent.CLICK, gearLoader);
btnGloves.addEventListener(MouseEvent.CLICK, gearLoader);
function handleImage(evtObj:Event):void{
//set initial position onstage
swfLoader.y = 56;
swfLoader.x = 244;
}[/AS]
So how do I pass the necessary parameters to the function below in a reasonably simple way? I’ve used event.target.name of a listener event object in other AS3 Projects to determine button clicked. . .but again, that does not help me with parameters.
New Function
[AS]function gearLoader(sItem:String, nSide:Number):void{
//dim Bitmap
mcProducts.alpha = 30;
//position clip
swfLoader.x = 244;
//fetch a swf
swfLoader.load(new URLRequest(sItem + ".swf"));
}[/AS]
I’ve looked through help files & articles but I’m certain I’m missing something simple here. Thanks Much!