A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] Dynamic access of object properties

  1. #1
    Member
    Join Date
    Mar 2004
    Posts
    89

    [RESOLVED] Dynamic access of object properties

    (continued from this thread)

    I'm looking for a clean way to set an object's properties without knowing ahead of time what kind of object it is or what the properties will be. For example, the object may be a VBox or HBox, in which case I will be setting height, width, border effects, etc, or it may be a TextField, in which case I will be setting font, fontsize, etc.

    I could spend lines and lines of code defining what properties to expect for what objects (not looking forward to that), but I was wondering if there is a dynamic way to handle this. For example, the XML object has an attribute array that contains the attribute names and values for a particular node. You can use the following to dynamically set those attributes:

    Code:
    myXML["id"] = "node1";
    Is there something similar for objects, i.e.:

    Code:
    myVBox["height"] = 150;
    ?
    Last edited by Upchurch; 08-09-2007 at 10:50 AM.

  2. #2
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,358
    myVBox["height"] = 150; will work if a) myVBox has the height property or b) myVBox (VBox?) is a dynamic class.

  3. #3
    Member
    Join Date
    Mar 2004
    Posts
    89
    Quote Originally Posted by senocular
    myVBox["height"] = 150; will work if a) myVBox has the height property or b) myVBox (VBox?) is a dynamic class.
    You're kidding me. It's just that simple? I assumed it wouldn't be since I didn't see any documentation that talked about that method of property access. That is way too cool.

    Just to verify:

    myVBox.height is equivalent to myVBox["height"]?

    ( where var myVBox:VBox = new VBox() )

  4. #4
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,358

  5. #5
    Member
    Join Date
    Mar 2004
    Posts
    89
    Damn you, Easily Accessible Information!



    (thanks)

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