A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] adding variables to movieClips?

  1. #1
    Pixel Artéést chriso20's Avatar
    Join Date
    Apr 2003
    Location
    Notts, UK
    Posts
    325

    resolved [RESOLVED] adding variables to movieClips?

    Hey,

    (Using AS3)

    I'm doing a simple grid layout of boxes (movieClips), i'm then trying to save their current position to each of the movieClips.

    So in AS2 i'd do something like ...

    obj.origX = obj._x;
    obj.origY = obj._y;

    but it's saying;

    1119: Access of possibly undefined property targetX through a reference with static type flash.displayisplayObject.



    How can i add custom variables to movieClips?

    Thanks!

  2. #2
    Pixel Artéést chriso20's Avatar
    Join Date
    Apr 2003
    Location
    Notts, UK
    Posts
    325
    The only way i can see to do it at the moment is having another object storing variables like this;

    anotherObject["mc"+a+"_"+b+"_x"] = obj.x;
    anotherObject["mc"+a+"_"+b+"_y"] = obj.y;

    (^ for use in a couple for loops, where a and b are variables to give reference to the movieClips)

    What you think? is this the way to do it?

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    MovieClips are dynamic, so you can add properties on the fly like you're trying to do. The error you get indicates that the compiler does not know that the object you are trying to add a dynamic property to is a MovieClip. All it knows is that it's a DisplayObject. DisplayObjects are NOT dynamic, so you can't necessarily add properties. So, to tell the compiler that the object actually is a MovieClip, cast it.

    Code:
    MovieClip(yourobject).targetX = someValue;
    Consider using specific classes that have the properties you want to use defined in the class definition. Not only is it easier from a type-correctness point of view, it is also slightly faster at runtime to find those properties.

  4. #4
    Pixel Artéést chriso20's Avatar
    Join Date
    Apr 2003
    Location
    Notts, UK
    Posts
    325
    AAAAAAaaaaaaaahhhh!


    Thanks for that, it alll becomes clear now... haha

    Cheers again

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