[FlashCS3/AS2] Unable to target dynamically created MC

Hi all,

I’m having trouble targeting a dynamically created, nested MC.

Basically, I’m creating a dropdown menu that populates according to data from an external XML file. Each of the instances of cityName_mc are dynamically created, named and positioned within cityName_genList_mc. This list will be long, so I will also need to make it scroll eventually. In preparation for this, I have created a MC called cityNameListMask_mc that will mask cityName_genList_mc. All of this is then within **cityDropList_mc **which doesn’t diplay the dropdown unless on frame three of the cityDropList_mc movieclip. So the nesting is basically:[INDENT] _root
…>cityDropList_mc (instance name: cityDropList_mc)
…>cityDropListMask_mc (instance name: cityDropListMask_mc) -MASK
…>cityDrop_genList_mc (instance name: cityDrop_genList_mc)
…>instances of cityName_mc (ex. Zurich_listItem)
[/INDENT]My issue is that I need each instance of cityName_mc to have an onRollOver and onRelease event, but I am somehow unable to target these MCs.

Below is a copy of my AS, a lot of which is for other parts of the project. I’ve bolded the AS that is relevant to my problem, however, I thought it would be prudent to include it all in case there is something elsewhere that someone thinks is interfering with my rollover/release events.

//START declare variables

// map zoom variables
_global.map_width_orig = _root.map_mc._width;
_global.map_height_orig = _root.map_mc._height;
_global.map_x_orig = _root.map_mc._x;
_global.map_y_orig = _root.map_mc._y;
_global.mapSize = "normal";

//city placement variables
_global.cityNum = 0;
_global.cityXCoord = 0;
_global.cityYCoord = 0;
_global.pulseMCinstName = "pulse";

//city pulse variables
_global.cityPulse = "off";

//category variables
_global.currentCategory = "ALL";

//custom cursor variable
_global.cursor = "arrow";

_global.inputA = "";

//strip string variables
_global.stringIn = "";
_global.stringOut = "";

//city dropdown variables
_global.cityDropStatus = "norm";
_global.cityNameFromList = "";
_global.cityInstName = "";

//END declare variables


//START declare functions

//the following function will expand the map to a larger size
function enlargeMap() {
    _root.map_mc._width = map_width_orig*3;//expands the width
    _root.map_mc._height = map_height_orig*3;//expands the height
    _root.map_mc._x = map_x_orig-map_width_orig;//sets the new x coordinate to center the map
    _root.map_mc._y = map_y_orig-map_height_orig;//sets the new y coordinate to center the map
    mapSize = "large";//sets the mapSize variable to large
    makeCustomCursor("hand");
}

//the following function will shrink the map to its original size
function shrinkMap() {
    _root.map_mc._width = map_width_orig;//shrinks the width
    _root.map_mc._height = map_height_orig;//shrinks the height
    _root.map_mc._x = map_x_orig;//sets the original x coordinate
    _root.map_mc._y = map_y_orig;//sets the original y coordinate
    mapSize = "normal";//sets the mapSize variable back to normal
    makeCustomCursor("arrow");
}

//the following function will change the cursor
function makeCustomCursor(cursor) {
    Mouse.hide();
    if (cursor == "pointer") {
        _root.cursorArrow_mc._visible = false;
        _root.cursorPointer_mc._visible = true;
        _root.cursorHand_mc._visible = false;
        _root.cursorFist_mc._visible = false;
    } else if (cursor == "hand") {
        _root.cursorArrow_mc._visible = false;
        _root.cursorPointer_mc._visible = false;
        _root.cursorHand_mc._visible = true;
        _root.cursorFist_mc._visible = false;
    } else if (cursor == "fist") {
        _root.cursorArrow_mc._visible = false;
        _root.cursorPointer_mc._visible = false;
        _root.cursorHand_mc._visible = false;
        _root.cursorFist_mc._visible = true;
    } else {
        _root.cursorArrow_mc._visible = true;
        _root.cursorPointer_mc._visible = false;
        _root.cursorHand_mc._visible = false;
        _root.cursorFist_mc._visible = false;
    }
    onMouseMove();
}

//the following functions causes the various cursors to follow the mouse
function onMouseMove() {
    _root.cursorArrow_mc._x = _root.cursorArrow_mc._parent._xmouse;
    _root.cursorArrow_mc._y = _root.cursorArrow_mc._parent._ymouse;
    _root.cursorPointer_mc._x = _root.cursorPointer_mc._parent._xmouse;
    _root.cursorPointer_mc._y = _root.cursorPointer_mc._parent._ymouse;
    _root.cursorHand_mc._x = _root.cursorHand_mc._parent._xmouse;
    _root.cursorHand_mc._y = _root.cursorHand_mc._parent._ymouse;
    _root.cursorFist_mc._x = _root.cursorFist_mc._parent._xmouse;
    _root.cursorFist_mc._y = _root.cursorFist_mc._parent._ymouse;
}

**//the following function populates the city dropdown list
function popCityDrop() {
    //declare variables to count all cities
    var countAllCities = "0";//declare variable to count all cities
    countAllCities = gv_event_xml.firstChild.firstChild.childNodes.length;
    var k = "0";
    //for loop to count cities with homepages in XML
    for (i=0; i<countAllCities; i++) {
        var hpCheck = gv_event_xml.firstChild.firstChild.childNodes*.attributes["homepage"];
        if (hpCheck !== "") {
            var cityNameFrom = gv_event_xml.firstChild.firstChild.childNodes*.attributes["cityname"];
            stripXtraCharas(cityNameFrom);
            cityNameFromList = stringOut;
            cityInstName = cityNameFromList+"_listItem";//declares the instance name of the movieclip
            _root.cityDropList_mc.cityDrop_genList_mc.attachMovie("cityName_mc",cityInstName,k+200);//attaches the movieclip, gives it the unique instance name, gives it a depth
            _root.cityDropList_mc.cityDrop_genList_mc[cityInstName]._x = 0;//moves the movieclip to the correct x coordinate
            _root.cityDropList_mc.cityDrop_genList_mc[cityInstName]._y = k*16;//moves the movieclip to the correct x coordinate
            _root.cityDropList_mc.cityDrop_genList_mc[cityInstName].cityName_txt.text = cityNameFrom;//adds name to the list item
            k++;
        }
    }
    //declare variables to move dropdown background to appropriate length
    var m = k*16;
    //move dropdown according to size of list
    if (m>=416) {
        _root.cityDropList_mc.cityDropListBG_mc._y = 45;
        _root.cityDropList_mc.cityDropListMask_mc._height = 416;
    } else {
        _root.cityDropList_mc.cityDropListBG_mc._y += m;
        _root.cityDropList_mc.cityDropListMask_mc._height = m;
    }
}**

//the following function removes all characters from a string except upper and lower case letters
function stripXtraCharas(stringIn) {
    stringOut = "";
    for (j=0; j<stringIn.length; j++) {
        if (stringIn.charAt(j) == "A" || stringIn.charAt(j) == "a" || stringIn.charAt(j) == "B" || stringIn.charAt(j) == "b" || stringIn.charAt(j) == "C" || stringIn.charAt(j) == "c" || stringIn.charAt(j) == "D" || stringIn.charAt(j) == "d" || stringIn.charAt(j) == "E" || stringIn.charAt(j) == "e" || stringIn.charAt(j) == "F" || stringIn.charAt(j) == "f" || stringIn.charAt(j) == "G" || stringIn.charAt(j) == "g" || stringIn.charAt(j) == "H" || stringIn.charAt(j) == "h" || stringIn.charAt(j) == "I" || stringIn.charAt(j) == "i" || stringIn.charAt(j) == "J" || stringIn.charAt(j) == "j" || stringIn.charAt(j) == "K" || stringIn.charAt(j) == "k" || stringIn.charAt(j) == "L" || stringIn.charAt(j) == "l" || stringIn.charAt(j) == "M" || stringIn.charAt(j) == "m" || stringIn.charAt(j) == "N" || stringIn.charAt(j) == "n" || stringIn.charAt(j) == "O" || stringIn.charAt(j) == "o" || stringIn.charAt(j) == "P" || stringIn.charAt(j) == "p" || stringIn.charAt(j) == "Q" || stringIn.charAt(j) == "q" || stringIn.charAt(j) == "R" || stringIn.charAt(j) == "r" || stringIn.charAt(j) == "S" || stringIn.charAt(j) == "s" || stringIn.charAt(j) == "T" || stringIn.charAt(j) == "t" || stringIn.charAt(j) == "U" || stringIn.charAt(j) == "u" || stringIn.charAt(j) == "V" || stringIn.charAt(j) == "v" || stringIn.charAt(j) == "W" || stringIn.charAt(j) == "w" || stringIn.charAt(j) == "X" || stringIn.charAt(j) == "x" || stringIn.charAt(j) == "Y" || stringIn.charAt(j) == "y" || stringIn.charAt(j) == "Z" || stringIn.charAt(j) == "z") {
            stringOut += stringIn.charAt(j);
        }
    }
}

//END declare functions


//START call functions

//the following executes functions for the test function button and is for TEST PURPOSES ONLY
**testFunction_mc.onRelease = function() {
    if (_root.cityDropList_mc.cityDrop_genList_mc.Zurich_listItem) {
        trace('mc exists');
        _root.cityDropList_mc.cityDrop_genList_mc.Zurich_listItem.gotoAndStop("over");
    } else {
        trace('mc DOES NOT exist');
    }
};**

//the following will execute the functions to enlarge and shrink the map when the zoom button is toggled
zoomMap_mc.onRelease = function() {//action will be execute on release
    if (mapSize == "normal") {//checks to see if the mapSize variable is normal
        enlargeMap();//executes the function to enlarge the map
        _root.zoomMap_mc.gotoAndStop('zoomOut');//goes to the 'zoomOut' label on the zoom button MC timeline
    } else {//will execute the following only if the mapSize variable is not normal
        shrinkMap();//executes the function to shrink the map
        _root.zoomMap_mc.gotoAndStop('zoomIn');//goes to the 'zoomIn' label on the zoom button MC timeline
    }
    makeCustomCursor("pointer");
};
zoomMap_mc.onRollOver = function() {//action will be executed on rollover
    makeCustomCursor("pointer");
};

/*zoomMap_mc.onRollOut = function() {//action will be executed on rollover
if (mapSize == "normal") {
makeCustomCursor("arrow");
} else {
makeCustomCursor("hand");
}
};*/

**_root.cityDropBar_mc.onRollOver = function() {//action will be executed on rollover
    makeCustomCursor("pointer");
    _root.cityDropBar_mc.gotoAndStop("over");
};
_root.cityDropBar_mc.onRelease = function() {//action will be executed on release
    makeCustomCursor("pointer");
    if (cityDropStatus == "norm") {
        _root.cityDropList_mc.gotoAndStop("open");
        cityDropStatus = "open";
    } else {
        _root.cityDropList_mc.gotoAndStop("norm");
        cityDropStatus = "norm";
    }
    popCityDrop();
};
_root.cityDropBar_mc.onRollOut = function() {//action will be executed on rollout
    _root.cityDropBar_mc.gotoAndStop("norm");
};
_root.cityDropList_mc.onRelease = function() {//action will be executed on release
    _root.cityDropList_mc.gotoAndStop("open");
};
_root.cityDropList_mc.onRollOver = function() {//action will be executed on release
    makeCustomCursor("arrow");
};

_root.cityDrop_genList_mc.Zurich_listItem.onRollOver = function() {
    _root.cityDropList_mc.cityDrop_genList_mc.Zurich_listItem.gotoAndStop("over");
    makeCustomCursor("pointer");
    trace('Rolling Over Zurich');
};**



//the following will execute the rollover highlight on the x-box
xbox_mc.onRollOver = function() {//executes the following on rollover
    _root.xbox_mc.gotoAndStop('over');//goes to the 'over' label on the x-box MC timeline
    makeCustomCursor("pointer");
};
xbox_mc.onRollOut = function() {//execute the following on rollout
    _root.xbox_mc.gotoAndStop('norm');//goes to the 'norm' label on the x-box MC timeline
    if (mapSize == "normal") {
        makeCustomCursor("arrow");
    } else {
        makeCustomCursor("hand");
    }
};

map_mc.onPress = function() {
    if (mapSize == "large") {
        startDrag(map_mc);
        _root.answer1 = "";
        makeCustomCursor("fist");
    }
    _root.cityDropList_mc.gotoAndStop("norm");
    _root.cityDropBar_mc.gotoAndStop("norm");
    cityDropStatus = "norm";
};
map_mc.onRelease = function() {
    if (mapSize == "large") {
        stopDrag();
        if (map_mc._droptarget == "/bow") {
            _root.answer1 = "Correct";
        } else {
            _root.answer1 = "wrong";
        }
        makeCustomCursor("hand");
    }
};
map_mc.onRollOver = function() {
    if (mapSize == "normal") {
        makeCustomCursor("arrow");
    } else {
        makeCustomCursor("hand");
    }
};

//END call functions


//START load event XML

var gv_event_xml = new XML();//creates new variable for event XML
var gv_city_xml = new XML();//creates new variable for city XML
gv_event_xml.ignoreWhite = true;//ignores white space in event XML file
gv_city_xml.ignoreWhite = true;//ignores white space in city XML file

//the following functions will execute when the event XML has finished loading
gv_event_xml.onLoad = function(success) {
    if (success) {
        //trace(this); 
    }
};

//the following functions will execute when the city XML has finished loading
gv_city_xml.onLoad = function(success) {
    if (success) {
        //placeCities();
        makeCustomCursor("arrow");
    }
};

gv_event_xml.load("GandV_events.xml");//loads the event XML into its variable
gv_city_xml.load("GandV_cities.xml");//loads the city XML into its variable 

//END load event XML

I have already tried several things to try to figure out what’s wrong but nothing seems to give me any insight.

Firstly, I thought that the paths to the instances of the cityName_mc MCs were wrong, but when I put in script to verify that the MC exists where I put it, it comes back that the MC does indeed exist. (Going further, I even used an external button to show the rollover effect when clicked and that works as well.) This leads me to believe that I’m targeting the MCs correctly.

Secondly, I thought (for whatever reason) that it was ‘nested too deeply’ so I moved cityDrop_genList_mc and its mask up to sit on the main timeline. That did not help and I’ve since put it back the way it was.

Thirdly, I thought that the mask was getting in the way of the mouse being detected on rollover of each of the MCs because it was covering them. I unmasked the containing MC and moved the mask out of the way, but it continued not to show the rollover effect.

At this point, I’m somewhat at a loss. Any help would be greatly appreciated.

Thank you.