At 10/13/09 08:19 PM, perj wrote:
hmm maybe this is more complicated than I expected it to be. I really thought this would be a simple thing - if not I feel like this is something that should be addressed. But what do I know.
Here is another example. AS3 is really nice as it's entirely Object Orientated.
In the library, you could have a movieclip that's exported for Actionscript in the properties with a class name of "ButtonObj"
You could have an (*.as) file in the com directory in the same folder as your fla/swf.
com/MyButton.as
package com
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import ButtonObj;
public class MyButton extends MovieClip
{
public var self:ButtonObj = new ButtonObj();
//you'll need to make a reference to the stage from a document class or any other method. Assume the name is "cur"
public function MyButton(x:Number = 0, y:Number = 0, link:String)
{
if (x == 0 || y == 0)
{
self.x = cur.stageWidth / 2;
self.y = cur.stageHeight / 2;
}
else
{
self.x = x;
self.y = y;
}
cur.addChild(self);
self.addEventListener(MouseEvent.MOUSE_UP, onBtnClick);
function onBtnClick(evt:MouseEvent):void
{
navigateToURL(new URLRequest(link));
}
}
}
}
then to refer to it anywhere, simply call:
var btn:MyButton = new MyButton(30, 70, "http://www.google.com");
You can create many references of MyButton without a problem. Hopefully that helped some!