A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Need help with declaring var for multiple functions

  1. #1
    Member
    Join Date
    Nov 2007
    Posts
    83

    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

  2. #2
    Member
    Join Date
    Aug 2010
    Posts
    65
    youre talking about classes, thats the only thing that can be created with "new", well jsut read up about basic as3 oop

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center