jeudi 28 mai 2015

Dealing with intances of MovieClips in AS3

I have been having trouble in getting data of MovieClips of the same names, yet stored inside different MovieClips all together.

What I Have:

  1. An Object with instance workScreen of class FashionFrenzy which contains all the rest of the MovieClips that I mention next.

Added using AS3 using addChild method in constructor code and function codes of workScreen:

  1. 12 Objects of class Shop which have a member displayArt of MovieClip type. These MovieClips are stored using an array shopMCs when then objects are created within a loop.

shopMCs array:

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);

All these MovieClips are present physically over workScreen. These link perfectly and do all the functions as required.

  1. This is where my problem comes. I made a new Object of instance realShop of Class RealShop. This real shop again contains all the MCs in the shopMC array with exactly same instance name so that I have better control.

Whenever the gameTimer ; object of of Timer Class in my game which controls all the time related things in my game; reaches a specified number, the function openDayEndScreen launches.

openDayEndScreen function:


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);

  for each(var buyer_mc: Buyer in buyers) {


  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) {
        //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



What this function is trying to do is place an Object of class UpgradeButton over respective MCs in the realShop , taking reference from the Shop class item's displayArt's postion; looper. I have marked down details in comments.

So, the compiler throws error when realShop.shopMCs[looper] is accessed.


TypeError: Error #1010: A term is undefined and has no properties. at FashionFrenzy/openDayEndScreen() at at at FashionFrenzy/checkDayTimerEnd() at flash.utils::Timer/_timerDispatch() at flash.utils::Timer/tick()

How do I acchieve what I want without compiler throwing errors?

Aucun commentaire:

Enregistrer un commentaire