A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Global variable problem

  1. #1
    Junior Member
    Join Date
    Apr 2007
    Posts
    14

    Question Global variable problem

    I load an image and add it to the MC someMC. If "something" is true, the someVariable gets the someMC scaleX number. Let's say its 0.82.

    What I need is to get that number into the s.value in my Slider object. Since I want the Slider value to be where my image scale is.

    This of course doesn't work because of variable scope limitations.

    I have tried setting the variable at the top of the code like this:
    var someVariable:Number;
    but that didn't work either.

    I'm looking for a solution without having to use package and class, since I'm not that steady with AS3 yet.


    Here's some illustration code, for the whole code see under this:
    Code:
    	function completeHandler(event:Event):void{
    		 if (something) {
    			  var someVariable:Number = this.someMC.scaleX;
    		 }
    	}   
    	
    	
    	var s:Slider = new Slider();
    	s.maximum = 500;
    	s.minimum = 10;
    	s.value = someVariable;

    I've uploaded all the code to Pastebin. Take a look



    Any thoughts?

  2. #2
    Flactionscrish Baby Minion's Avatar
    Join Date
    Nov 2005
    Location
    Planet Earth
    Posts
    312
    Right now that code will not work because you are declaring the somVariable inside the scope of the completeHandler function. That means when the completeHandler is done, the variable someVariable will go away.
    You will need to declare that variable outside of that function first, so that 's' can utilize it later.

    I am surprised the code you posted at Pastebin doesn't throw any errors for you. I looked through the whole thing, and the variable sliderValue is never declared.

    However, it seems like what I suggest should fix it for you. See what happens.
    ktu[k-two]
    he who hesitates is lost; so i guess i'll wander intently

    Are you sure this is real?
    Life is Love, Love is Blind, Blind we go through Life.
    Life isn't hard, dealing with your self is.

    The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.


  3. #3
    Junior Member
    Join Date
    Apr 2007
    Posts
    14
    Hi, like I said in my original post, I have already tried to declare it. When I do, I only get a NaN when I trace it at the bottom where the s vars is. Any thoughts?

  4. #4
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    you need to put slider inside a function because the complete handler hasn't executed before your trace at the bottom executes try this.

    PHP Code:
    var someVariable:Number;
    var 
    s:Slider;
    function 
    completeHandler(event:Event):void{
             if (
    something) {
                   
    someVariable this.someMC.scaleX;

             }
                 
    = new Slider();
        
    s.maximum 500;
        
    s.minimum 10;
        
    s.value someVariable;

        } 
    ~calmchess~

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