A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: undefined variables?

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    13

    undefined variables?

    Hi
    I defined a variable in frame one of my flash as =0, and when it goes to frame 2 it says this variable is undefined. I tried the same with a boolean variable and it also says false for frame one, but changes to undefined when it enters frame 2
    Any suggestions as to why it is doing this?
    Thanks

  2. #2
    Ozzy the Grey
    Join Date
    Sep 2007
    Posts
    61
    var numVar:Number = 0;
    put this in the actions panel on frame 1

  3. #3
    Senior Member
    Join Date
    Jun 2008
    Posts
    549
    You need to declare the variable by adding 'Var' before your code.

  4. #4
    Junior Member
    Join Date
    Aug 2009
    Posts
    13
    I put var numVar:Number = 0; in frame one in the actions layer (in scene 2 where I need it) and it's still saying undefined when I enter frame 2

  5. #5
    Ozzy the Grey
    Join Date
    Sep 2007
    Posts
    61
    sample file please

  6. #6
    Senior Member
    Join Date
    Jun 2008
    Posts
    549
    have you tried adding the code in frame 2, or alternatively you can declare a global variable.

  7. #7
    Junior Member
    Join Date
    Aug 2009
    Posts
    13
    Quote Originally Posted by ilike2 View Post
    have you tried adding the code in frame 2, or alternatively you can declare a global variable.
    I only want the variable to be 0 when it is initially loaded which is why I put it in frame 1. You have to go and find objects in other frames which will change the variable, and then you can see which objects you've found in frame 2 because the variable has changed.

  8. #8
    Senior Member
    Join Date
    Jan 2003
    Location
    Nebraska
    Posts
    448
    You have a .fla file? Not sure what is happening to cause this. Is the variable being set at the _root or inside a movieclip?
    Var keyword is not needed in AS2 (although recommended).
    ecards - My full flash site.

  9. #9
    Junior Member
    Join Date
    Aug 2009
    Posts
    13
    I used _root and it worked

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