我有什么:
我想做的事情:
当我们点击买家时,如果买家2的条件已满,则1. y> = 377或者已成为= = true,则选择买方并将其保存到买方的selectedBuyer变量中。
之后,当我点击商店时,如果商店的买家对象" shoppingBuyer"为null,选定的买方被指定为shoppingBuyer并运行计时器。否则显示消息不会发生。
当计时器结束时,启动一个功能" shopGetOut"它允许买方离开商店并使购买者的商店和商店的买主无效,并以这样的方式重置商店,使其现在也可以被其他买方对象所接受。
我收到错误的地方
最初,一切都很好。但是随着越来越多的买家对象被包含在内,不知何时购物者没有被分配并保持为空,但这并不是所有时间都只发生过几次。
跟踪/访问specefic Shop对象的shoppingBuyer时出错:
TypeError:错误#1009:无法访问空对象引用的属性或方法。 在FashionFrenzy / shopGetOut() 在flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() 在Shop / addTime() 在flash.utils :: Timer / _timerDispatch() 在flash.utils :: Timer / tick()
当它跟踪商店的displayAll()时这样:
正确显示: 店铺名称:上衣 购物买家:null
错误显示: 商店名称:电影 TypeError:错误#1009:无法访问空对象引用的属性或方法。 在FashionFrenzy / shopGetOut() 在flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() 在Shop / addTime() 在flash.utils :: Timer / _timerDispatch() 在flash.utils :: Timer / tick()
有时甚至商店名称也没有跟踪
我的代码:
我的职能:
点击商店时:
public function shopselected(event: SelectEvent): void {
if (SelectedBuyer != null) { //checks if we actually selected a buyer before we clicked a shop
if (SelectedBuyer.previousShop == event.selectedshop) {
trace("You just went in there"); // this is to not let a buyer enter the same shop they have been before to.
} else {
SelectedBuyer.currentShop = event.selectedshop; // changes the current shop which was previously null to the shop they are in right now
SelectedBuyer.shopping = true;
SelectedShop = event.selectedshop; // the clicked shop becomes selected shop
trace(SelectedShop.ShopName);
if (SelectedShop.ShoppingBuyer == null && SelectedShop.ShopName != "Counter") { //check if someone is already shopping in that shop or if it's the counter
SelectedShop.ShoppingBuyer = SelectedBuyer;
SelectedShop.InWork(); // this starts a timer of the shop and when desired timer is reached, it dispatches the ShopOverEvent which runs the function shopGetOut.
if (SelectedBuyer.enteredMall == true) {
dispatchEvent(new AssignEvent(AssignEvent.MIDDLE, SelectedBuyer.previousShop.ShopNumber)); //this has nothing to do with my probelm
} else {
dispatchEvent(new AssignEvent(AssignEvent.ENTRY, SelectedBuyer.laneNo)); //this has nothing to do with my probelm
}
SelectedBuyer.enteredMall = true;
SelectedBuyer.x = SelectedShop.Displayart.x + 20;
SelectedBuyer.y = SelectedShop.Displayart.y - 20;
} else { //this all is working fine from 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 is already there");
}
}
}
removeChild(SelectBuyerOverlay);
} else {
trace("Please Select a Buyer first");
}
SelectedBuyer = null;
SelectedShop = null;
}
在买家购物的时候商店的计时器达到限度的时候:
public function shopGetOut(event: ShopOverEvent): void {
event.shopEnd.shopTimer.stop(); // the timer which was started is set off.
event.shopEnd.ShoppingBuyer.y += 80; // the buyer is shifted out of the shop
event.shopEnd.ShoppingBuyer.shopping = false; // buyer is no longer shopping
event.shopEnd.ShoppingBuyer.previousShop = event.shopEnd; //current shop is made previous shop
event.shopEnd.ShoppingBuyer.currentShop = null; // current shop is made null
dispatchEvent(new AssignEvent(AssignEvent.MIDDLE, event.shopEnd.ShopNumber)); // this nullifies previous shop nothing to do with my problem
event.shopEnd = null;
}
如果我能用更好更简单的代码做同样的事情而不会出现错误,我会很高兴。