1 Reply Latest reply on Sep 11, 2013 1:24 AM by moccamaximum

    AS3 coding - movie in swf file doesn't show

    Charine -FB buggoop Level 1

      I would be so greatful if someone can help with this. I've been sitting for days to find my mistake but my inexperience really holds me back here

       

      In my spelling game I have letters falling out of the sky - players have to click on them. I tested one letter in this swf. It works as I planned but it was only one letter hard coded.

       

      So now I have many levels and I added the letters needed for each level in arrays generated through a loop. They trace correctly, but they do not show up in this swf.

       

      I'm sure I am just missing a bit of code in the function or didn't addChild correctly. I doubble checked that the missing MC is not behind the background by turning the backgroung off, but it is not that.

       

      Where am I going wrong?

       

      Here is the relevant code:

       

      package

       

      {

          import flash.display.*;

          import flash.text.TextField;

          import flash.events.Event;   

          import flash.utils.Timer;

          import flash.events.*;

          import flash.events.MouseEvent;

          import flash.media.Sound;

          import flash.media.SoundChannel;

       

          public  dynamic class WordArray extends MovieClip

              {

                      public var wordtext:wordText =  new wordText;

                      var activeWordArray:Array;

                      var activeLevelofTenWordsArray:Array;

                     var activeLevelofTilesArray:Array;

                      public var letterArray:LetterArray;

                      var tileTimer = new Timer(500,384);

       

              //Movie clips of letter tiles to be used

              public var a:A = new A();

              public var f:F = new F();

              public var g:G = new G(); //etc. for all mc's

       

              private var wordArray:WordArray;

       

              private var letterTiles:Array = [a,f,g..etc];

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

                                    private var  lettersL02:Array = [th,th,  //etc for all levels..

       

                                  public var letterLevels:Array = [lettersL01,lettersL02,lettersL03,lettersL04,lettersL05,lettersL06,le ttersL07,lettersL08,lettersL09,lettersL10,

                                                                                    lettersL11,lettersL12,lettersL13,lettersL14,lettersL15,lettersL16,let tersL17,lettersL18,lettersL19,lettersL20,

                                                                                    lettersL21,lettersL22,lettersL23,lettersL24,lettersL25,lettersL26,let tersL27,lettersL28,lettersL29,lettersL30];

       

      public var  wordsL1W1:Array = ["a"];  //etc for all words

       

      public var  wordsL01:Array = [wordsL1W1,...etc for all levels];

       

      public var wordLevels:Array = [wordsL01,wordsL02,...etc. for entire word array]

       

                      private var tf:TextField;

       

                      // ***constructor code

                      public function WordArray(_tf:TextField)

                      {   

                          tf = _tf;

                          levelGenerator();

       

                      }

       

                      function levelGenerator():void

                      {

                          //**To get next level of 10 words

                          if(wordLevels.length>0)

                          {

                              activeLevelofTenWords();

                              tileGenerator();

                          }

                          else

                          {

                          //Game is complete

                          }

                      }

       

                      function activeLevelofTenWords():void

                      {

                          // na

                      }

       

                      function tileGenerator():void

                      {

                          if(letterLevels.length>0)

                              {

                                  activeLevelofTiles();

                              }

                          else

                              {

                                  //Game is complete

                              }

       

                          }

       

      function activeLevelofTiles():void

                          {

                              activeLevelofTilesArray = letterLevels.shift();

                          initLetterTiles();

                          }

                         

                          function initLetterTiles():void

                           {

                              for(var j:int=0; j<3; j++)

                               {  shuffle(activeLevelofTilesArray);

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

                                  {

                                      trace (activeLevelofTilesArray[i]);

                                      activeLevelofTilesArray[i].x = 399;

                                      activeLevelofTilesArray[i].y= 30;

                                      addChild(activeLevelofTilesArray[i]);

                                  }

                              }

                          }

       

                                  function shuffle(a:Array)

                                  {

                                      var p:int;

                                      var t:*;

                                      var ivar:int;

                                      for (ivar = a.length-1; ivar>=0; ivar--)

                                          {

                                          p=Math.floor((ivar+1)*Math.random());

                                          t = a[ivar];

                                          a[ivar] = a[p];

                                          a[p] = t;

                                          }

       

                                  }

        • 1. Re: AS3 coding - movie in swf file doesn't show
          moccamaximum Level 5

          part of your problem could be that I am only seeing that you create one instance of every letter but using this letter multiple times in your Arrays

           

          check this code:

           

          var a:A = new A();

          addChild(a);

          addChild(a);

          addChild(a);

          addChild(a);

          addChild(a);

          addChild(a);

           

           

          for (var i:int = 0; i<=stage.numChildren-1;i++){

              trace("checking");

              if (getChildAt(i) is A){

                  trace("A found");

              }

          }

           

          Flash will throw no error and you might think that you actually put multiple instances of A on stage, but in fact Flash only creates one instance.

           

           

           

           

          similar thing with your code:

           

          [a,a,f,f,f,g,g,h,h,i,i,n,n,n,o,o,o,o,s,s,t,t,t];

          ...

          addChild(activeLevelofTilesArray[i]);

           

          will not add multiple instances of your objects if you only use the new keyword once for every letter.

           

           


          Another thing: Why do you need WordArray to be dynamic?

          Using dynamic has some caveats: http://flexblog.faratasystems.com/2006/10/02/actionscript-3-dynamic-classes

          1 person found this helpful