-
Need help with declaring var for multiple functions
hi, how to declare a variable that can be accessible for some functions, and recreatible with "new" command, using or without using packages?
Code:
function showWindow(event:MouseEvent):void {
currentButton = event.target.name;
var holder:DisplayObjectContainer=new DisplayObjectContainer();
addChild(holder);
loader = new SWFLoader("swf/showwindow.swf", {onComplete:onLoadSWF, container:holder, width:200, height:200, x:0, y:0, hAlign:"left", vAlign:"top", centerRegistration:true});
addChild(loader.content); //add the ContentDisplay to the display list even before raw content is loaded.
loader.load();
}
function onLoadSWF(event:LoaderEvent):void {
mc = loader.rawContent; //the root of the child swf
mc.close_btn.addEventListener(MouseEvent.CLICK, closeSwf);
mc.topBar_mc.addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);
mc.topBar_mc.addEventListener(MouseEvent.MOUSE_MOVE, follow);
mc.topBar_mc.addEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
setChildIndex(cursor_mc, numChildren-1);
holder.x=200;
holder.y=200;
// Detect which button was clicked
if (currentButton=="instanceCapitalLettersShow") {
mc.show_txt.text=onCapitalClick();
} else if (currentButton=="instanceSmallLettersShow") {
mc.show_txt.text=onSmallClick();
} else if (currentButton=="instanceNumbersShow") {
mc.show_txt.text=onNumbersClick();
}
}
my problem is two functions can't use one variable "holder". can anyone help me?
i m using greensock swfloader
Last edited by onurcan1977; 04-13-2011 at 04:45 PM.
Reason: what i m using
-
youre talking about classes, thats the only thing that can be created with "new", well jsut read up about basic as3 oop
-
Your holder variable is declared inside showWindow, so it is local to that function. You must declare it at a higher scope in order for it to be available to other functions.
Of course, there's no reason you actually need it in the other function since you could set the x and y in the first one.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|