actionscript 3 - Logic for a function in AS3 giving error for unknown reason -


what have:

  1. buyer class. objects of buyer class generated along game time , stored in array : buyers.
  2. shop class. objects of shop class generated in begining of program.
  3. event "assign event" nullifies "shoppingbuyer" of buyer type of shop object.

what i'm trying do:

when click buyer, if buyer's 2 conditions fullfilled 1. y>=377 or enteredmall==true, buyer selected , saved selectedbuyer variable of buyer.

after that, when click shop, if shop's buyer object "shoppingbuyer" null, selected buyer assigned shoppingbuyer , timer runs. otherwise message displayed cannot happen.

when timer over, function launched "shopgetout" lets buyer out of shop , nullifies buyer of shop , shop of buyer , resets shop in such way can acccesible other buyer object now.

where i'm getting error:

initially, works good. more , more buyer objects included, somehow shoppingbuyer not being assigned , stays null doesn't happen times few times.

error when trace/ access shoppingbuyer of specefic shop object :

typeerror: error #1009: cannot access property or method of null object reference. @ fashionfrenzy/shopgetout() @ flash.events::eventdispatcher/dispatcheventfunction() @ flash.events::eventdispatcher/dispatchevent() @ shop/addtime() @ flash.utils::timer/_timerdispatch() @ flash.utils::timer/tick()

like when traces displayall() of shop:

correct display: shop name: tops shopping buyer: null

error display: shop name: movies typeerror: error #1009: cannot access property or method of null object reference. @ fashionfrenzy/shopgetout() @ flash.events::eventdispatcher/dispatcheventfunction() @ flash.events::eventdispatcher/dispatchevent() @ shop/addtime() @ flash.utils::timer/_timerdispatch() @ flash.utils::timer/tick()

and shop name isn't traced out well

my code:

my functions:

when shop clicked:

public function shopselected(event: selectevent): void {      if (selectedbuyer != null) { //checks if selected buyer before clicked shop      if (selectedbuyer.previousshop == event.selectedshop) {       trace("you went in there"); // not let buyer enter same shop have been before to.      } else {       selectedbuyer.currentshop = event.selectedshop; // changes current shop null shop in right        selectedbuyer.shopping = true;         selectedshop = event.selectedshop; // clicked shop becomes selected shop       trace(selectedshop.shopname);        if (selectedshop.shoppingbuyer == null && selectedshop.shopname != "counter") { //check if shopping in shop or if it's counter         selectedshop.shoppingbuyer = selectedbuyer;          selectedshop.inwork(); // starts timer of shop , when desired timer reached, dispatches shopoverevent runs function  shopgetout.          if (selectedbuyer.enteredmall == true) {            dispatchevent(new assignevent(assignevent.middle, selectedbuyer.previousshop.shopnumber)); //this has nothing probelm         } else {           dispatchevent(new assignevent(assignevent.entry, selectedbuyer.laneno)); //this has nothing probelm         }          selectedbuyer.enteredmall = true;         selectedbuyer.x = selectedshop.displayart.x + 20;         selectedbuyer.y = selectedshop.displayart.y - 20;                 } else { //this working fine here.         if (selectedshop.shopname == "counter") {           selectedbuyer.x = selectedshop.displayart.x + 20;           selectedbuyer.y = selectedshop.displayart.y - 20;           if (selectedbuyer.enteredmall) {             dispatchevent(new assignevent(assignevent.middle, selectedbuyer.previousshop.shopnumber));           } else {             dispatchevent(new assignevent(assignevent.entry, selectedbuyer.laneno));           }            removechild(selectedbuyer);         } else {           trace("someone there");         }         }     }     removechild(selectbuyeroverlay);   } else {     trace("please select buyer first");   }   selectedbuyer = null;   selectedshop = null;  } 

when timer of shop reaches limit while buyer shopping:

public function shopgetout(event: shopoverevent): void {     event.shopend.shoptimer.stop(); // timer started set off.   event.shopend.shoppingbuyer.y += 80; // buyer shifted out of shop   event.shopend.shoppingbuyer.shopping = false; // buyer no longer shopping    event.shopend.shoppingbuyer.previousshop = event.shopend; //current shop made previous shop    event.shopend.shoppingbuyer.currentshop = null; // current shop made null    dispatchevent(new assignevent(assignevent.middle, event.shopend.shopnumber)); // nullifies previous shop nothing problem     event.shopend = null;    } 

i'll glad if same better , easy code without error coming.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -