Accessing dynamically added MC from library n as3

I have a library item that I’m exporting with a class name as infobox.

I load it onto my stage as such:

var boxy:infobox = new infobox();
			boxy.name = "boxy"; 
			stage.addChild(boxy); 

Then inside of another function I’m trying to access it this way :

private function onTriggerCollide(trigger:Trigger):void{
			trace("I hit"); 
			
			b=stage.getChildByName("boxy"); 
			
			b.gotoAndPlay(1); 
		}

But I get this error:

C:\Users\Public\Documents\AA success\myMovie.as, Line 73 1120: Access of undefined property b.

undefined property? I should be able to access a movie clip on the stage like that, right? I think I done this before.

I DO import import flash.display.MovieClip at beginning of the script.

any help would be appreciated !! thanks.

-s:)

OK, I figured out my problem:

this line:

b=stage.getChildByName("boxy"); 

should really be like called like this:

var b:MovieClip=MovieClip(stage.getChildByName("boxy")); 

It was my ActionScript 2 gremlin coming back to visit for a moment. I had forgotten to declare a type for “b” and I had to downcast stage.getChildByName(“boxy”) to a MovieClip because I think
stage.getChildByName(“boxy”) returns a DisplayObject.

so yeah. problem solved! :slight_smile: