开发者

How to create a custom property/method inside a MovieClip? (AS3)

I'm programming a kind of "Lights Off" game in Flash Professional (not Flash/Flex Builder) and it would be very nice if I could manage on/off state in a grphically designed S开发者_运维百科ymbol like this:

square1.on();
/* calling this method produces the same as */
square1.on = true;
square1.gotoAndStop("onState");

/* obviously, the next method: */
square1.off();
/* will produce */
square1.on = false;
square1.gotoAndStop("offState");

Is this possible? How do I create the custom on property and custom methods on() and off()? If not possible, what else can I do? Thank you.


Use a property like state and create two functions to change that state and navigate the playhead.

Also, you should be extending MovieClip to create these custom properties... better practice.

class MySquare extends MovieClip {
    public function on ():void {
        this.state = 'on';
        this.gotoAndStop('onState');
    }
    public function off ():void {
        // same, but for off
    }

[Tutorial] Export for ActionScript


You have to make your own class, that extends MovieClip like this:

public class CustomMovieclip extends MovieClip
{
   public function CustomMovieclip() {
     //constructor, here you do any initialization stuff
   {

   public function on() {
     //here you turn on the lights
   {

   public function off() {
     //here you turn off the lights
   {
}

And then you can simply call them like this:

var bulb = new CustomMovieclip();
bulb.off();


I have a movie clip called btn1 for which I needed a custom property "sel" (for selected state)

This is how I used it.

btn1.sel = 1;

You can also add new properties like

btn1.name = "Prabhat";

Or

btn1.selected = false;

Hope this helps.. although i see its a quite old post..just in case if you still need the info

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜