[RESOLVED] Questions about Variables
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] Questions about Variables

  1. #1
    Senior Member
    Join Date
    Aug 2005
    Posts
    170

    [RESOLVED] Questions about Variables

    1. what is different between:
    Code:
    Set Variable: "bob" = 5
    and
    Code:
    bob = 5
    i have read a few things and not much describing how thay are different.
    2. Var is like a temporary Variable right? so it deletes itself once it's used right?

  2. #2
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,668
    no var is not temporary. I have never had a var delete itself or used a set variable.
    .

  3. #3
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    hi blue you must be thinking about a varibale defined within a function. if you define a variable in a function, that variable is available only within that function and as soon as the function has run it will go back to being undefined.

    have a look at this to get a better understanding

    Code:
    hello();
    
    function hello(){
    
    trace("first call: " + greeting);
    	
    var greeting:String = "hello there";
    
    trace(greeting)// this will output 'hello there'
    }
    
    trace(greeting) // this will output undefined
    
    hello(); // this will help u to see that the variable was destroyed as the first call  will now say undefined
    Last edited by silentweed; 04-04-2006 at 08:25 AM.
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  4. #4
    Senior Member
    Join Date
    Aug 2005
    Posts
    170
    yeah thats what i ment so thanks.
    1.what is different between:
    Code:
    Set Variable: "bob" = 5
    and
    Code:
    bob = 5
    i have read a few things and not much describing how thay are different.
    Last edited by -Blue-; 04-04-2006 at 08:28 AM.

  5. #5
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    Personally ive never myself or seen anyone else create a variable using the 'Set' keyword within flash? Does this techinque even exist?

    ( the only place i use Set w.r.t variables is in my ASP pages)

    cosider the following variable

    var greeting:String = "hello there";
    //this variable is available everywhere


    function sums(){

    var someN:Number = 5; //this is available only within this function due to using the var keyword
    }

    function sumMore(){

    someN = 5; // as we have not used the var keyword it is just the same as defining this variable on the timeline that this function exists (although i woudnt recommend this method)
    }


    Hope this helps..
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  6. #6
    Senior Member
    Join Date
    Aug 2005
    Posts
    170
    ah! so using "var bob" is sorta like using "_global.bob" and "_root.bob"
    sorta being key word cuz i know they are different.
    Am i on the right track?
    yes or no?
    Last edited by -Blue-; 04-08-2006 at 01:27 AM.

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