1 Reply Latest reply on Jul 16, 2006 8:11 AM by Newsgroup_User

    Storing details of objects in an array in a class

    P Steven Level 1
      Hi there

      New to all this class malarkey so having some teething problems and could do with some help.

      I have written a function to display 10 stars on screen using attachMovie

      i.e

      var vStar_Object = attachMovie(vLinkage_Name, vInstance_Name, vDepth);

      I later need to access these star objects to enable me to animate them to certain positions on screen.

      I am therefore trying to create a starManager class to store the details of these star objects.

      Here is my class so far:

      #############################

      class classes.starManager {

      // -----------
      // Constructor
      // -----------

      public function starManager() {


      trace ("starManager class constructor");

      var List_Of_Star_Objects:Array = new Array();



      }



      // ---------------
      // Add Star Object
      // ---------------

      public function Add_Star_Object(passed_Star_Object:Object):Void {


      List_Of_Star_Objects.push(passed_Star_Object);


      }



      }

      #################################

      I have created an instance of this class as follows:

      myStarManager = new starManager();

      Therefore in the loop that creates my 10 star objects I call the function "Add_Star_Object" as follows:

      myStarManager.Add_Star_Object(vStar_Object);


      However I am getting the following error message:

      There is no method with the name 'List_Of_Star_Objects'.
      List_Of_Star_Objects.push(passed_Star_Object);


      Any ideas what I am doing wrong here or suggestions as how this is best done. Basically I need to store some reference to my star objects and I do not want to use globals.

      Thanks in advance

      Paul

        • 1. Re: Storing details of objects in an array in a class
          Level 7
          Before the constructor method
          // Class variables
          private var List_Of_Star_Objects:Array();

          In the constructor method
          change var List_Of_Star_Objects:Array = new Array();
          to List_Of_Star_Objects:Array = new Array();
          or this.List_Of_Star_Objects:Array = new Array();


          I recommend not capitalizing the first letter of variable names. Initial
          caps normally indicates a class name.



          --
          Lon Hosford
          www.lonhosford.com
          Flash, Actionscript and Flash Media Server examples:
          http://flashexamples.hosfordusa.com
          May many happy bits flow your way!
          "ChuckyLeFrek" <webforumsuser@macromedia.com> wrote in message
          news:e9d1f9$av0$1@forums.macromedia.com...
          > Hi there
          >
          > New to all this class malarkey so having some teething problems and could
          > do
          > with some help.
          >
          > I have written a function to display 10 stars on screen using attachMovie
          >
          > i.e
          >
          > var vStar_Object = attachMovie(vLinkage_Name, vInstance_Name, vDepth);
          >
          > I later need to access these star objects to enable me to animate them to
          > certain positions on screen.
          >
          > I am therefore trying to create a starManager class to store the details
          > of
          > these star objects.
          >
          > Here is my class so far:
          >
          > #############################
          >
          > class classes.starManager {
          >
          > // -----------
          > // Constructor
          > // -----------
          >
          > public function starManager() {
          >
          >
          > trace ("starManager class constructor");
          >
          > var List_Of_Star_Objects:Array = new Array();
          >
          >
          >
          > }
          >
          >
          >
          > // ---------------
          > // Add Star Object
          > // ---------------
          >
          > public function Add_Star_Object(passed_Star_Object:Object):Void {
          >
          >
          > List_Of_Star_Objects.push(passed_Star_Object);
          >
          >
          > }
          >
          >
          >
          > }
          >
          > #################################
          >
          > I have created an instance of this class as follows:
          >
          > myStarManager = new starManager();
          >
          > Therefore in the loop that creates my 10 star objects I call the function
          > "Add_Star_Object" as follows:
          >
          > myStarManager.Add_Star_Object(vStar_Object);
          >
          >
          > However I am getting the following error message:
          >
          > There is no method with the name 'List_Of_Star_Objects'.
          > List_Of_Star_Objects.push(passed_Star_Object);
          >
          >
          > Any ideas what I am doing wrong here or suggestions as how this is best
          > done.
          > Basically I need to store some reference to my star objects and I do not
          > want
          > to use globals.
          >
          > Thanks in advance
          >
          > Paul
          >
          >
          >