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


can please?

 

in output have:

+++ welcome screen +++ +++ levels screen +++ >>> array: 0,0,1,1 >>> random numbers: 3 >>> random numbers: 2 >>> random numbers: 1 >>> random numbers: 0 ****** icons creationg finished ****** level: 1 started typeerror: error #1009: cannot access property or method of null object reference.      at mymatching/stopwatch()[d:\#_flash_games\matchingthings\mymatching.as:70] icon 0 clicked icon 0 clicked + added 20 points because matching of 2 icons. player has: 20 points --- deleted 2 icons --- icon 1 clicked icon 1 clicked + added 20 points because matching of 2 icons. player has: 40 points --- deleted 2 icons --- +++ gameover screen +++ 

 

code:

package  {      import adobe.utils.customactions;      import flash.display.movieclip;      import flash.events.mouseevent;      import flash.text.textfield;      import flash.events.*;      import flash.utils.gettimer;       public class mymatching extends movieclip      {           public var xiconscontainer;//all icons start draw x           public var yiconscontainer;//all icons start draw y                      private var iconsvertical=2;//icons columns           private var iconshorizontal=2;//icons rows                      private var firsticon;//player click first icon           private var secondicon;//player click second icon                      private var deletedicons:int = 0;//if firsticon==secondicon delete 2 icons           public var numberoflevels:int = 2;//2 1 level; 4 1, 2 levels; 6 1, 2, 3 levels                      public var starttime:int = gettimer();           public var timestring:string;                      public var playerscoresum:int = 0;//sum of players points                      public var iconslist:icon;           public var iconsarray:array;                      public var iconwidth:int = 51;//width of icon           public var iconheight:int = 51;//height of icon                      public var levelnumber:int = 1;                      public var matchpoints:int = 20;//if player match 2 icons add 20 points playerscoresum           public var misspoints:int = 1;//if miss delete 1 points playerscoresum                      //constructor           public function mymatching()           {                welcomescreen();           }                      public function welcomescreen():void           {                trace("+++ welcome screen +++");                gotoandstop('welcomescreen');                playbtn.addeventlistener(mouseevent.click, gotolevels);           }                      public function startingstopwatch():void          {                addeventlistener(event.enter_frame, stopwatch);          }                     public function stopingstopwatch():void          {                removeeventlistener(event.enter_frame, stopwatch);          }                    public function stopwatch(event:event)          {                var timepassed:int = gettimer()-starttime;                var seconds:int = math.floor(timepassed/1000);                var minutes:int = math.floor(seconds/60);                seconds -= minutes*60;                timestring = minutes + ":" + string(seconds + 100).substr(1, 2);                stopwatchpreview.text = string(timestring);         }                      public function gotolevels(event:mouseevent)           {                xiconscontainer=stage.stagewidth/2 - (iconwidth*iconshorizontal)/2;//all icons start draw x                yiconscontainer=stage.stageheight/2 - (iconheight*iconsvertical)/2;//all icons start draw y                startingstopwatch();                                trace("+++ levels screen +++");                iconsarray = new array();//creating new object iconsarray                                     gotoandstop('levels');                                for (var i:int; < iconsvertical*iconshorizontal/2; i++)                {                     iconsarray.push(i);                     iconsarray.push(i);                }                trace(">>> array: " + iconsarray);                                                                                    for (var x:int = 0; x < iconsvertical; x++)                {                     for (var y:int = 0; y < iconshorizontal; y++)                     {                          iconslist = new icon();                          addchild(iconslist);                          iconslist.buttonmode = true;//if move cursor icon can see hand                          iconslist.stop();//stoping our icons on flash ide, because on 1 layer have our icons                          iconslist.x=x*iconwidth+xiconscontainer;                          iconslist.y=y*iconheight+yiconscontainer;                          var myrandom:int=math.floor(math.random()*iconsarray.length);//creates random number related index of array named "iconsarray"                          //var showicon;//cast whatever type of element array holding                          iconslist.showicon=iconsarray[myrandom];//assigns randomly selected element of iconsarray variable showicon                          iconsarray.splice(myrandom,1);//removes randomly selected element (now showicon) array (not last one, random one) //we use splice command remove number array won’t used again                          //iconslist.gotoandstop(iconslist.showicon+2);//showicon+2 next frame in timeline after frame random item deleted, code moving in timeline frame after frame item removed array                          trace(">>> random numbers: " + myrandom);                          iconslist.addeventlistener(mouseevent.click, clicktoicon);                          deletedicons++;//when draw icons every time add +2 icons our deletedicons variable, in future deleted 2 icons variable if firsticon==secondicon                     }                }                                //added score sceen                trace("****** icons creationg finished ******");                trace("level: " + levelnumber + " started");                //levelnumberpreview.text = string(levelnumber);                          }                                public function clicktoicon(event:mouseevent)           {                var thisicon:icon = (event.currenttarget icon);//what icon player clicked...                trace("icon " + thisicon.showicon + " clicked");//trace clicked icon output pannel                if (firsticon==null)                {                     firsticon=thisicon;                     firsticon.gotoandstop(thisicon.showicon + 2);                }                 else if (firsticon == thisicon)                {                     firsticon.gotoandstop(1);                     firsticon=null;                }                 else if (secondicon==null)                {                     secondicon=thisicon;                     secondicon.gotoandstop(thisicon.showicon + 2);                                          if (firsticon.showicon==secondicon.showicon)                     {                          playerscoresum += matchpoints;// add matchpoints existing player points                          scoregamepreview.text = string(playerscoresum);                          trace("+ added " + matchpoints + " points because matching of 2 icons. " + "now player has: " + playerscoresum + " points");                                                    removechild(firsticon);                          removechild(secondicon);                          deletedicons -= 2;                          trace("--- deleted 2 icons ---");                          if (deletedicons == 0)                          {                               if (iconsvertical >= numberoflevels)                               {                                    iconsvertical = 2;                                    iconshorizontal = 2;                                    levelnumber = 1;                                    movieclip(root).playerscoresum = playerscoresum;                                    stopingstopwatch();                                    starttime = gettimer();                                    gotoandstop('gameoverscreen');                                    trace("+++ gameover screen +++");                               }                               else                               {                                    iconsvertical += 2;                                    iconshorizontal += 2;                                    levelnumber += 1;                                    xiconscontainer+=2;                                    yiconscontainer+=2;                                    gotolevels(null);                               }                                                        }                     }                     else                     {                          playerscoresum -= misspoints;// delite misspoints existing player points                          scoregamepreview.text = string(playerscoresum);                          trace("- deleted " + misspoints + " points because missing of 2 icons. " + "now player has: " + playerscoresum + " points");                     }                }                else                {                     firsticon.gotoandstop(1);                     secondicon.gotoandstop(1);                     firsticon = null;                     secondicon = null;                     firsticon=thisicon;                     firsticon.gotoandstop(thisicon.showicon + 2);                }           }                            } } 

the 1009 error indicates 1 of objects being targeted code out of scope.  mean object....


 
- not in display list
- doesn't have instance name (or instance name mispelled)
- not exist in frame code trying talk it
- animated place not assigned instance names in every keyframe it
- 1 of 2 or more consecutive keyframes of same objects different names assigned.
 
if go publish settings flash section , select option permit debugging, error message should have line number following frame number isolate object involved.


More discussions in ActionScript 3


adobe

Comments

Popular posts from this blog

Joomla site hacked, cant see front and - Joomla! Forum - community, help and support

Christian Home School Programs - Joomla! Forum - community, help and support

Trouble with PF_OutFlag_I_USE_AUDIO and PF_CHECKOUT_LAYER_AUDIO