Quantcast
Channel: Adobe Community : All Content - Adobe Animate CC - General
Viewing all articles
Browse latest Browse all 13519

Building a simple TIMER

$
0
0

In my word game, I have 30 Levels of letter tiles falling out of the sky.

 

I want to control these arrays(of movie clips) with a timer, so that I can start, pause and stop it at specific times.

 

I'm doing something wrong with the timer code. This is the error message I get:

 

TypeError: Error #1009: Cannot access a property or method of a null object reference.

    at WordArray/startTileTimer()

    at WordArray/activeLevelofTiles()

    at WordArray/tileGenerator()

    at WordArray/levelGenerator()

    at WordArray()

    at wordText/initWordText()

    at flash.display::DisplayObjectContainer/addChild()

    at BugGoopFSGame/startTimer()

 

How do I fix the timer? Should I have added it as an event listener somehow?

 

Relevant code below:

 

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;

                public var tileTimer:Timer;

           

     

        //Movie clips of letter tiles to be used

        public var a:A = new A();

        public var f:F =  //...etc

 

        private var wordArray:WordArray;

       

        private var letterTiles:Array = [a,f,g,h,i,...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

                           

                            public var letterLevels:Array = [lettersL01,lettersL02,lettersL03,...etc];

           

public var  wordsL1W1:Array = ["a"];

public var  wordsL1W2:Array = ["h","a","s"];

//...etc

 

public var  wordsL01:Array = [wordsL1W1,wordsL1W2,wordsL1W3,wordsL1W4,wordsL1W5,wordsL1W6,wordsL1W 7,wordsL1W8,wordsL1W9,wordsL1W10];

public var  wordsL02:Array = [wordsL2W1,  //...etc.

public var wordLevels:Array = [wordsL01,wordsL02,wordsL03,...etc]

                                               

                private var tf:TextField;

               

                // ***constructor code

                public function WordArray(_tf:TextField)

                {   

                   tf = _tf;

                    levelGenerator();

                    var tileTimer = new Timer(500,384);

                }

               

                function levelGenerator():void

                {

                   //**To get next level of 10 words

                    if(wordLevels.length>0)

                    {

                        activeLevelofTenWords();

                        tileGenerator();

                   }

                    else

                    {

                    //Game is complete

                    }

                }

               

                function activeLevelofTenWords():void

                {

                    //**To get next word

                    activeLevelofTenWordsArray = wordLevels.shift();

                    nextWordF();

                }

               

                function tileGenerator():void

                {

                    if(letterLevels.length>0)

                    {

                        activeLevelofTiles();

                    }

                    else

                    {

                    //Game is complete

                    }

                 

                    }

                   

                    function activeLevelofTiles():void

                    {

                        activeLevelofTilesArray = letterLevels.shift();

                        shuffleTiles(activeLevelofTilesArray);

                        trace(activeLevelofTilesArray);

                        startTileTimer();

                    }

                   

                    function shuffleTiles(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;

                                    }

                        }

                       

                    function startTileTimer():void

                        {

                            tileTimer.start();

 

                            //Place the tiles to run

 

                            /*activeLevelofTilesArray.x = 399;

                            activeLevelofTilesArray.y= 30;

                            addChild(activeLevelofTilesArray);*/

                            trace("Letters should run");

                        }

                       

               //rest of code not applicable

                }

        }


Viewing all articles
Browse latest Browse all 13519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>