PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] dynamic variables HELP!
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [RESOLVED] dynamic variables HELP!

  1. #1
    AS3 N00B
    Join Date
    Feb 2002
    Location
    NYC
    Posts
    308

    resolved [RESOLVED] dynamic variables HELP!

    Actionscript Code:
    var preBar01:Number = 0.47;

    trace(preBar01)           // i get this: 0.47
    var i:Number = 1;
    trace(["preBar0"+i])      // i get this: preBar01
    trace(this["preBar0"+i])  // i get this: undefined

    I do not understand why i am getting undefined on the last trace. Thanks in advance
    -Neo

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    That is probably code in a frame on a movieclip. Such code is transparently transformed into a function which is called on entering that frame, and consequently all variables defined in that code are local variables to that function.

  3. #3
    AS3 N00B
    Join Date
    Feb 2002
    Location
    NYC
    Posts
    308
    I am not sure if I understand what your saying but that code is already IN a function.

    Actionscript Code:
    function ParseSeriesData(seriesInput:XML):void {
      //code in first post goes here
    }

    Its a function called on once the XML is loaded. Everything else is working fine.
    -Neo

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    That's what I was saying. Variables declared in a function are local to that function. They are not properties on an object.

  5. #5
    AS3 N00B
    Join Date
    Feb 2002
    Location
    NYC
    Posts
    308
    Well everything I'm doing is in ONE function only, the variable is declared within the function as well. I am not using a variable from a different function.

    Thank you for your help and sorry if I'm a little slow in trying to understand your point.
    -Neo

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    When you use the bracket syntax to access a property, you are accessing a property of a particular object.
    Code:
    this["preBar01"]
    will return the value of the preBar01 property of the object in the current scope (in your case, the movie clip in which that function is written). There IS no such property, because preBar01 is a local variable, not a property.

  7. #7
    AS3 N00B
    Join Date
    Feb 2002
    Location
    NYC
    Posts
    308
    oooooooooohhhh i get what your saying, i have to create the variable outside the function first.

    thank you again for all your help. you have been very helpful lately.
    Last edited by neo1487; 03-07-2010 at 10:09 PM.
    -Neo

  8. #8
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Well, sort of. Even if you declare the variable in the frame outside of that function, it is probably still going to end up in the generated function corresponding to that frame code.

    To set a property within frame script, you might need to set using this. or this[propertyname].

    In a class, obviously, you don't need to worry about the generated function for frame script.

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