Link to home
Start Free TrialLog in
Avatar of ugeb
ugebFlag for United States of America

asked on

accessing library items in as3 file

Hi,

I have a fla file with lots of library items. I can access them inside actionscript that is inside the fla file itself, but how can an external class in an external file access them?

E.g. I have arms.fla with library item Box that's a MovieClip. In an external file NumberLine.as I need the Box item for display. I've already exported Box for actionscript, but I still get compile errors. How do I get Box into NumberLine.as?

Thanks!
Avatar of julianopolito
julianopolito
Flag of Brazil image

is numberline just a external script, or it is a class?
sorry,  I think my question was not correct. You cannot have compile problems since the fla will always compile library items before compiling the scripts. Can you send the source code of the as file? What exactly is the compiler error you are getting?
Avatar of ugeb

ASKER

Well, I don't know what I did, but it seems to recognize Box now.  However, I can't seem to add it as a child to the class because it doesn't know what addChild is.

If I take out that line, it compiles and runs, but of course I need that in there.  

Any ideas?
Thanks!



package {
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.display.SimpleButton;
	import Box1;
 
	public class NumberButton extends SimpleButton
	{
		var id:Number;
		var whichPic:String;
		var highlightBox:Box1;
		
		public function NumberButton() {
				trace("new NumberButton");
				this.addEventListener(MouseEvent.CLICK, onClick);
				this.addEventListener(MouseEvent.MOUSE_OVER, showBox);
				this.addEventListener(MouseEvent.MOUSE_OUT, hideBox);
				
				highlightBox = new Box1(29,10);
				this.addChild(Box1);
				highlightBox.visible = false;
				}
		
		public function setID(idNum:Number):void
		{
			id=idNum;
		}
 
		public function setPic(whichPicArg:String):void {
			whichPic=whichPicArg;
				trace("Creating NumberButton:   id = " + id + ",    whichPic = " + whichPic);
		}
		
		private function onClick(evt:MouseEvent):void
		{
			trace(" * * * * * * clicked button " + id);
		}
 
		private function showBox(evt:MouseEvent):void
		{
				highlightBox.visible = true;
		}
		
		private function hideBox(evt:MouseEvent):void
		{
				highlightBox.visible = false;
		}
	}
	
}

Open in new window

Avatar of ugeb

ASKER

The error is:

1061: Call to a possibly undefined method addChild through a reference with static type NumberButton.

the problem is not the library item. You are probably trying to add the child to a non DisplayObjectContainer. What is NumberButton? Is it a container object, like Stage, Sprite or MovieClip? addChild Method is only available to container objects. Can you post the complete AS code so I can see where you are making the mistake?
sorry, i did not see it was above
ASKER CERTIFIED SOLUTION
Avatar of julianopolito
julianopolito
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ugeb

ASKER

Okay, didn't realize buttons couldn't have children.  Thanks for the solution!