Skip navigation
Currently Being Moderated

Link between classes: Reference Error

May 21, 2013 10:43 AM

Hi,

I am still trying to create a movie clip array to make a list of objects appear on stage and have the user interact with them.

 

This will be my game loop class called "LetterArray()".

My main class is called "BugGoopFSGame()".

 

After I add the line of code below into my LetterArray(). as class file I get the error message below:

 

Code entered:

 

private var  lettersL1:Array = new Array[a,f,g,h,i,n,o,s,t];

 

This is the error message I get:

 

ReferenceError: Error #1069: Property [object T] not found on S and there is no default value.

    at LetterArray()

    at BugGoopFSGame()

 

I am sure the reference I use between the two files are not good. Can you please tell me what code I should add and where.

 

Thanks for your help!

Charine

 

This is the code in my main class - BugGoopFSGame()

 

package

{

    import flash.display.*;

    import flash.utils.Timer;

    import flash.events.*;

    import flash.events.MouseEvent;

    import flash.media.Sound;

    import flash.events.Event;

    import flash.media.SoundChannel;

    import flash.media.SoundMixer;

    import flash.media.SoundTransform;

    import flash.text.*;

    import flash.net.URLRequest;

 

    public class BugGoopFSGame extends MovieClip

    {

        public var mybackground:BackGround;

        public var letterArray:LetterArray = new LetterArray(stage); //this is how I link from main to gameloop

 

 

This is the coce in my gameloop class - LetterArray()

 

package

{

    import flash.display.*;

    import flash.events.*;

    import flash.text.*;

    import flash.utils.Timer;

    import flash.media.Sound;

    import flash.media.SoundChannel;

    import flash.net.URLRequest;

 

 

 

    public class LetterArray extends MovieClip

    {

        private var _stage:Stage; //this reference works well to the main file. Should I somehow link it to the errorous code below?

       

        /*Movie clips that need to go into an array    */

        //level 1

        public var a:A = new A();

        public var f:F = new F();

        public var g:G = new G();

        public var h:H = new H();

        public var i:I = new I();

        public var n:N = new N();

        public var o:O = new O();

        public var s:S = new S();

        public var t:T = new T();

       

        private var letterArray:Array;

        private var  lettersL1:Array = new Array[a,f,g,h,i,n,o,s,t]; //this is the line that causes the error. I am sure it is because I need to add something to the main class.

 
Replies
  • kglad
    72,235 posts
    Jul 21, 2002
    Currently Being Moderated
    May 21, 2013 11:37 AM   in reply to Charine -FB buggoop

    if, for example, A is a class name, you should use "A" and then use getDefinitionByName() to retrieve the class reference from the string.

     

    private var  lettersL1:Array = new Array['A','F','G','H','I','N','O','S','T'];

     

    .

    .

    .

    for(var i:int=0;i<lettersL1.length;i++){

    var C:Class=Class(getDefinitionByName(lettersL1[i]));  // import flash.utils.getDefinitionByName

    var c:*=new C(); // create instances from the classes in lettersL1

    // do whatever with c

    }

     

     

    or, move those instanciation statements into your LetterArray constructor or somewhere beyond like:

     

    package

    {

        import flash.display.*;

        import flash.events.*;

        import flash.text.*;

        import flash.utils.Timer;

        import flash.media.Sound;

        import flash.media.SoundChannel;

        import flash.net.URLRequest;

     

     

     

        public class LetterArray extends MovieClip

        {

            private var _stage:Stage; //this reference works well to the main file. Should I somehow link it to the errorous code below?

          

            private var letterArray:Array;

            private var  lettersL1:Array; //this is the line that causes the error. I am sure it is because I need to add something to the main class.

           

            public function LetterArray(ss:Stage):void{

                var a:A = new A();

                var f:F = new F();

                 etc

           

                lettersL1 = [a,f,...]

                _stage = ss;

            }

           

        }

    }

     
    |
    Mark as:
  • kglad
    72,235 posts
    Jul 21, 2002
    Currently Being Moderated
    May 25, 2013 2:51 PM   in reply to Charine -FB buggoop

    that for-loop should be in a function body.  eg, use:

     

    package

    {

        import flash.display.*;

        import flash.events.*;

        import flash.text.*;

        import flash.utils.Timer;

        import flash.utils.getDefinitionByName;

        import flash.media.Sound;

        import flash.media.SoundChannel;

        import flash.net.URLRequest;

     

     

        public class LetterArray extends MovieClip

        {

        

            private var  lettersL1:Array = new Array [A,F,G,H,I,N,O,S,T]; //these are movie clips for which classes were created dynamically by Flash

           

    public function LetterArray{

            for(var i:int =0; i <lettersL1.length; i++) //Line 21

                {

                var C:Class=Class(getDefinitionByName(lettersL1[i]));

                var c:*=new C(); // create instances from the classes in lettersL1

                                            // do whatever with c

                }

     

    }

    }

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points