A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Custom Object with dot Format

  1. #1
    Junior Member
    Join Date
    Nov 2003
    Posts
    19

    Custom Object with dot Format

    This is kind of a stupid question...

    How can I create a custom object with properties grouped together using dot format? Sort of like the TextFormat Object....

    I tried this, but it doesn't quite work

    var myObject:Object = new Object();
    myObject.groupOne.prop1 = "prop1";
    myObject.groupOne.prop2 = "prop2";

    myObject.groupTwo.prop1 = "prop1a";
    myObject.groupTwo.prop2 = "prop2a";

    myObject.groupThree.prop1 = "prop1b";
    myObject.groupThree.prop2 = "prop2b";
    myObject.groupThree.prop3 = "prop3b";

  2. #2
    FK's Giant Steve_w_V's Avatar
    Join Date
    Mar 2003
    Location
    San Jose, California
    Posts
    2,113
    This works:
    code:
    if (myObj == undefined) {
    myObj = new Object();
    }
    myObj.prop1 = "prop1";
    myObj.prop2 = "prop2";
    trace(myObj.prop1);
    trace(myObj.prop2);


    You can add more properties to it as necessary. The first bit of code is required, I dunno why, just is. It basically asks Flash if there is something somewhere named "myObj". Since there is not (undefined), make it.

    The next bit is assigning properties and values to those properties.

    Hope this helps.
    The other day, I bought a box of animal crackers. On the side, it said "Do Not Eat if Seal is Broken". I opened the box and sure enough...

  3. #3
    Deathbringer sylkro's Avatar
    Join Date
    Oct 2000
    Location
    London
    Posts
    202
    Your problem is that your code doesn't define what groupOne, groupTwo or groupThree are. this will make your code work:

    Code:
    var myObject:Object = new Object();
    
    var myObject.groupOne:Object = new Object();
    myObject.groupOne.prop1 = "prop1";
    myObject.groupOne.prop2 = "prop2";
    
    var myObject.groupTwo:Object = new Object();
    myObject.groupTwo.prop1 = "prop1a";
    myObject.groupTwo.prop2 = "prop2a";
    
    var myObject.groupThree:Object = new Object();
    myObject.groupThree.prop1 = "prop1b";
    myObject.groupThree.prop2 = "prop2b";
    myObject.groupThree.prop3 = "prop3b";

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