在AS3中处理MovieClip的实例

时间:2015-05-29 04:27:04

标签: actionscript-3 flash instance

我一直无法获取相同名称的MovieClips数据,但却存储在不同的MovieClips内。

我有什么:

  1. 具有类workScreen的实例FashionFrenzy的对象,其中包含我接下来提到的MovieClips的所有其余内容。
  2. addChild的构造函数代码和函数代码中使用workScreen方法使用AS3添加:

    1. 12类商品的对象,其成员displayArt类型为MovieClip。当在循环内创建对象时,使用MovieClips存储这些array shopMCs
    2. shopMCs数组:

      shopMCs = new Array(Snacks_mc,Jewellery_mc,Music_mc,Tops_mc,Bottoms_mc,Movies_mc,Purses_mc,Shoes_mc,Groceries_mc,Electronics_mc,Furniture_mc,Watches_mc,Counter_mc);
      

      所有这些MovieClips在物理上都存在于workScreen.这些链接完美,并根据需要执行所有功能。

      1. 这就是我的问题所在。我创建了一个类realShop的实例RealShop的新Object。这个真正的商店再次包含shopMC阵列中所有具有完全相同实例名称的MC,以便我有更好的控制权。
      2. 每当gameTimer;我游戏中Timer类的对象,它控制着我游戏中所有与时间相关的事物;达到指定的数字后,函数openDayEndScreen启动。

        openDayEndScreen函数:

        public
        
        function openDayEndScreen(event: DayEndEvent) {
        
          // I am perfectly sure this event is being dispatched and this function is running.
          Time_mc.gameTimer.removeEventListener(TimerEvent.TIMER, GenerateBuyers);
          Time_mc.gameTimer.reset();
        
        
          for each(var buyer_mc: Buyer in buyers) {
            removeChild(buyer_mc);
        
        
          }
        
          buyers.splice(0, buyers.length); // till here I have no troubles.
        
          realShop.x = 0;
          realShop.y = 0;
          addChild(realShop); // I have placed realShop.
          shopMCs = new Array(Snacks_mc, Jewellery_mc, Music_mc, Tops_mc, Bottoms_mc, Movies_mc, Purses_mc, Shoes_mc, Groceries_mc, Electronics_mc, Furniture_mc, Watches_mc, Counter_mc); // this is the array
        
          //shops is the array containing all the Shop objects. 
          for (var bigLooper: int = 0; bigLooper < shops.length; bigLooper++) {
            //bigLooper goes to each shop one by one.
            for (var looper: int = 0; looper < shopMCs.length; looper++) {
              //looper checks for the place in shopMc where the MovieClip instance is same as the displayArt.
              if (shopMCs[looper] == shops[bigLooper].displayArt) {
                break;
                //looper is saved.
              }
            }
        
            if (shops[bigLooper].shopOpen) {
              upgrade_btn = new UpgradeButton; //NOT throwing errors.
              trace(realShop.shopMCs[looper]); // I am trying to access the SAME MOVIECLIP instance in the     realShop; all these are throwing errors.
              upgrade_btn.x = realShop.shopMCs[looper].x; //all these are throwing errors.
              upgrade_btn.y = realShop.shopMCs[looper].y; //all these are throwing errors.
              addChild(upgrade_btn); //NOT throwing errors.
        
            } else { //do nothing for a while
        
            }
          }
        
        
        
        }
        

        此函数尝试执行的操作是将UpgradeButton类的对象放在MCs中相应的realShop上,并参考Shop类项{{1}位置; displayArt。我在评论中记下了细节。

        因此,当访问looper时,编译器会抛出错误。

        错误:

          

        TypeError:错误#1010:术语未定义且没有属性。在   FashionFrenzy / openDayEndScreen()at   flash.events :::EventDispatcher / dispatchEventFunction()at   flash.events :::EventDispatcher / dispatchEvent()at   FashionFrenzy / checkDayTimerEnd()at   flash.utils :: Timer / _timerDispatch()在flash.utils :: Timer / tick()

        如果没有编译器抛出错误,我如何能够获得我想要的东西?

0 个答案:

没有答案