dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: How Can We declare Arrays of any Object

  1. #1
    Junior Member
    Join Date
    Aug 2008
    Posts
    2

    How Can We declare Arrays of any Object

    Can Any one out there Please Acnowledge me that how can we declare and use array of an object of user defined class.
    I'll be waiting for any reply anxiously!
    Thank You

  2. #2
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    What exactly is not working for you? You should be able to put anything you like into an array. Are you trying to put references to instances of these classes, the class names?
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  3. #3
    Junior Member
    Join Date
    Aug 2008
    Posts
    2

    Thanks For Your Reply

    Infact I have got a Class:
    package ecard
    {
    import mx.controls.Alert;
    import mx.controls.Button;
    import mx.controls.Image;
    public class NewObject
    {
    public var myButton:Button;
    public var x1:int;
    public var y1:int;

    public function NewObject()
    {
    myButton = new Button();
    myButton.label = "I'm a button!";

    }

    public function create():void
    {
    myButton.x = x1;
    myButton.y = y1;
    y1 += 50;

    }

    }
    }

    Now I can create its object as:
    private var Ob1:NewObject = new NewObject();

    And can create a new button at runtime in a hbox present in the application:
    hbx1.addChild(Ob1.myButton);

    Now the thing is that it can create a button on runtime, but I want to create array of 'Ob1' which is object of class NewObject so that I may keep track of all the button objects created and may change their x & y axis etc...

    It will be really so nice of you to help me out in this situation
    Thanks a lot Once again!

  4. #4
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Well I don't know the rest of the logic for the application and how you will create new button instances, but as far as putting them into an array goes:
    var myButtons:Array = new Array();
    myButtons.push(Ob1.myButton);
    myButtons.push(Ob2.myButton);

    And so on each time you add a new button.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  5. #5
    Member
    Join Date
    Sep 2002
    Location
    Seattle
    Posts
    93
    Another option might be to use a Dictionary object.

    Bye now,

    Greg

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