Skip navigation
Currently Being Moderated

Putting Arrays to work: error 1065

Jun 20, 2013 4:34 PM

Hi all,

 

I have created this array which works well:

 

function initLetters():void

        {                               

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

            {

                trace (lettersL1[i]); // traces perfectly

 

             }

 

My next question: I want to do a lot of stuff with the objects in this array, (like suffle, appear at a certain x,y coordinate, change alpha, move along a path etc. All of wich I need to learn yet LOL)

                             Someone suggested that I add the following code to create a var to do this. When I add this I get the error code below. Is this the righ way to go for what I want?  Maybe it is in the wrong spot again?

 

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

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

                                        // do whatever with c*/

 

When I uncomment the above I suddenly get this error code:

 

ReferenceError: Error #1065: Variable [object A] is not defined.

    at global/flash.utils::getDefinitionByName()

    at LetterArray/initLetters()

    at LetterArray()

    at BugGoopFSGame()

 

My .as class code:

 

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 _stage:Stage;

 

        //Movie clips to be used

        public var a:A = new A();//etc

 

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

 

        //Text Fields and Format

                                                            //works well

                                                      //Sound Specs

                                                            //works well

 

        //***CONSTRUCTOR FUNCTION***

 

 

        public function LetterArray(s:Stage)

 

        {

            _stage = stage;

 

            trace("Main construtor is working");

 

            //GameLoop

            initText();

            initLetters();

            initLetterWasClickedOn();

            initCheckIfLetterIsCorrect();

            initInGameAnimation();

            initRemoveLetterChildren();

            initPointsGiven();

        }

 

    //OTHER FUNCTIONS

 

        function initText():void

                {                               

                    // text formatting: general

                 }

 

        function initLetters():void

        {                               

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

            {

                trace (lettersL1[i]); //trace works well

 

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

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

                                        // do whatever with c

            }

 
Replies
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 20, 2013 4:56 PM   in reply to Charine -FB buggoop

    do you have classes that match the contents of your array?

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 21, 2013 5:44 PM   in reply to Charine -FB buggoop

    if tracing lettersL1 does not yield strings (like "A","F",etc), you're not using getDefinitionByName correctly.

     

    in particular, if tracing lettersL1 yields a list of objects, you don't have strings in lettersL1.

     

    if that doesn't solve the problem for you, copy and paste lettersL1.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 24, 2013 3:40 PM   in reply to Charine -FB buggoop

    then use:

     

    lettersL1[i].x =

    lettersL1[i].y=

    lettersL1[i].alpha=

    // i have no idea how you want to implement a path or even what you mean.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 24, 2013 9:39 PM   in reply to Charine -FB buggoop

    if you have classes a,b,c,d defined and

     

    var lettersL1:Array=[a,b,c,d,...];

     

    you could use:

     

     

            function initLetters():void

            {           

    var prevX:int=0;                   

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

                {                   

    var letter:*=new lettersSl1[i]();

    letter.x = prevX;

    prevX+=letter.width+5;

    _stage.addChild(letter);

    }

    }

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 25, 2013 10:17 AM   in reply to Charine -FB buggoop

    does lettersL1 look like message 8?

     

    if yes, use that code to create objects.  if no, show lettersL1

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 26, 2013 5:09 AM   in reply to Charine -FB buggoop

    you're welcome.

     
    |
    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