Search code examples
actionscript

addEventListener only triggers on 2nd click


I'm trying to figure out why my addEventListener only triggers on second click. It works as expected but im not entirey sure why it's not triggering on initial click.

Here's my current code. The code below allows me to select a individual movieclip and change it's hue accordingly.

var SHELL = _global.getCurrentShell();
var INTERFACE = _global.getCurrentInterface();
function setupOutfit() {
    trace("Outfit Editor v1.2b Loaded ");
    if(SHELL.currentSavedOutfits === undefined && INTERFACE.currSlot === undefined) {
        return (false);
    }
    OUTFIT.gotoAndStop(2);
    OUTFIT.outfit_txt.text = INTERFACE.currSlot.name;
    OUTFIT.close_btn.onRelease = INTERFACE.closeContent;
    for (var f in penguin_layers) {
        setDollOutfit(penguin_layers[f], INTERFACE.currSlot[penguin_layers[f]]);
    }
    var _loc3 = Number(SHELL.getPlayerHexFromId(INTERFACE.currSlot.color));
    SHELL.setColourFromHex(OUTFIT.paper_doll_mc.body, Number(_loc3));
}

function setDollOutfit(type, id) {
    var dollDepth = OUTFIT.paper_doll_mc.createEmptyMovieClip("pd_" + type + "Clip", SHELL.PAPERDOLL_DEFAULT_LAYER_DEPTHS[type]);
    var dollClip = dollDepth.createEmptyMovieClip("itemClip", dollDepth.getNextHighestDepth());
    if (id > 0) {
        var _loc9 = id + ".swf";
        var dollLoader = new com.cp.hybrid.HybridMovieClipLoader();
        dollLoader.loadClip(SHELL.getPath("clothing_paper") + _loc9, dollClip);
    }
    updateItemInteractivity(type);
} 
function updateItemInteractivity(type) {
    var _loc2 = OUTFIT.paper_doll_mc["pd_" + type + "Clip"];
    if (_loc2 === null) {
        return (false);
    } 
    _loc2.onRelease = com.cp.util.Delegate.create(this, setOptionSection, type);
} 
function setOptionSection(type) {
    OUTFIT.options_mc.gotoAndStop(2);
    OUTFIT.options_mc.option_txt.text = "Editing " + type + " item";
    setHueClip = OUTFIT.paper_doll_mc["pd_" + type + "Clip"];
    OUTFIT.options_mc.huevalue_mc.addEventListener("change", this.setupItemHueModifier);
}

function setupItemHueModifier(evnt) {
    var _loc3 = new flash.filters.ColorMatrixFilter();
    var _loc1 = new com.gskinner.geom.ColorMatrix();
    _loc1.adjustHue(evnt.target.value);
    trace("Hue Value: " + evnt.target.value);
    _loc3.matrix = _loc1;
    setHueClip.filters = [_loc3];
}


var setHueClip;
var OUTFIT = outfitContainer_mc;
var penguin_layers = ["head", "face", "body", "neck", "hand", "feet"];
setupOutfit();

Solution

  • Fixed!

    Added onEnterFrame to the movieclip that way addEventListener is assigned to each type as it enters the frame.