You have 2 possibilities.
1. Create a movie with a movieclip in the library and link it to the class ChildSprite.
Then create a document class.PHP Code:package
{
import flash.display.MovieClip;
public class ChildSprite extends MovieClip
{
public function ChildSprite ()
{
this.buttonMode = true;
this.addEventListener("click", onClick);
}
private function onClick (obj:Object)
{
trace("Hello World");
}
}
}
In the Document class field in the fla add: Example and test movie.PHP Code:package
{
import flash.display.MovieClip;
import ChildSprite;
public class Example extends MovieClip
{
private var myBut:MovieClip;
public function Example()
{
var myBut:ChildSprite = new ChildSprite();
addChild(myBut);
myBut.x = 100;
myBut.y = 100;
}
}
}
2. Create a movie with a movieclip in the library and link it to the class ChildSprite_2, which is basically empty.
Then create a document class.PHP Code:package
{
import flash.display.MovieClip;
public class ChildSprite_2 extends MovieClip
{
public function ChildSprite_2 ()
{
}
}
}
This last example is closer to the original stage example.PHP Code:package
{
import flash.display.MovieClip;
import ChildSprite_2;
public class Example_2 extends MovieClip
{
private var myBut:MovieClip;
public function Example_2 ()
{
var myBut:ChildSprite_2 = new ChildSprite_2 ();
addChild(myBut);
myBut.x = 100;
myBut.y = 100;
myBut.buttonMode = true;
myBut.addEventListener("click", onClick);
}
private function onClick (obj:Object)
{
trace("Hello World");
}
}
}
A third possibility is this to mark the movieclip as button.
and then an above script as document class without the buttonmode.PHP Code:package
{
import flash.display.MovieClip;
public class ChildSprite_2 extends MovieClip
{
public function ChildSprite_2 ()
{
this.buttonMode = true;
}
}
}





Reply With Quote