Unable to Access Custom Property

Hi,

I keep getting the error “1119: Access of possibly undefined property isSelected through a reference with static type flash.display:DisplayObject.”.

Consider this code:


//Create Navigation Holder
var mcNavContainer:MovieClip = new MovieClip();
mcNavContainer.name = "mcNavContainer";

//XML Event Load Handler
function xmlLoaded(e:Event):void {
...
//Add To DisplayList
addChild(mcNavContainer);
//Create mcNavTitle from Instance of NavTitle
var mcNavTitle:NavTitle = new NavTitle();
//Default
mcNavTitle.isSelected = false;
trace(mcNavTitle.isSelected) //false (traces ok, no errors)
//Click Event
mcNavItem.addEventListener(MouseEvent.CLICK, mcNavItemClick);
//Add to DisplayList
mcNavContainer.addChild(mcNavItem);
mcNavItem.mouseChildren = false;
mcNavItem.buttonMode = true;

//mcNavItem Click
function mcNavItemClick(e:MouseEvent):void {
    //Set Target
    var mcTarget = e.currentTarget;
    //Highlight
    for(var i:Number = 0; i < mcNavContainer.numChildren; i++) {
        trace(mcNavContainer.getChildAt(i).isSelected); //traces as an error
    }
}

Basically I have a MovieClip (mcNavContainer) to hold many Objects (mcNavTitle) that are generated based on XML Rules (that I have not shown). I then set the property ‘isSelected’ to each of these.

I can trace ‘isSelected’ no problem from withing the XML function when referencing the Object’s variable name… However when I use the getChildAt style its throwing an error. If I trace(mcNavContainer.getChildAt(i)); it comes up with the Object as I would expect and is exactly the same as when it is accessed in the XML function.

Whats going on? I’m sure my logic is right but for some reason it keeps saying the property does not exist, does it have something to do with the XML not actually being generated when Flash reads the code therefore throws an error?

How can I fix this?

Cheers,
Ryan

Nevermind got it working :slight_smile:


//mcNavItem Click
function mcNavItemClick(e:MouseEvent):void {
    //Set Target
    var mcTarget = e.currentTarget;
    //Highlight
    for(var i:Number = 0; i < mcNavContainer.numChildren; i++) {
        if (mcNavContainer.getChildAt(i) is NavItem) {
            var setRef:MovieClip = MovieClip(mcNavContainer.getChildAt(i));
            trace(setRef.isSelected);
        };
    };
}

Thank you senocular for this post (http://www.kirupa.com/forum/showpost.php?p=2120340&postcount=363)