A bitmap like a button?

How to set a bitmap as a button so that I can apply button mode and mouse event material to it without adding a bitmap to the video clip?

var bmpFull=new Bitmap(event.currentTarget.content.bitmapData);
        bmpFull.smoothing=true;
        bmpFull.name="photo";
        bmpFull.alpha=0;

        //fullMC.buttonMode=true;
        fullMC.addChild(bmpFull);
+3
source share
2 answers

Unfortunately, Bitmap objects do not extend to the InteractiveObject class, i.e. they do not have (and cannot easily get) the ability to receive mouse events.

As pointed out by Antara and Jeremy White in the previous answer, the simplest container class that receives mouse events is the Sprite class. Therefore, if you want the bitmap to accept mouse events and not use MovieClip, you can use Sprite:

var bmpFull:Bitmap = new Bitmap(event.currentTarget.content.bitmapData);
bmpFull.smoothing = true;
bmpFull.name = "photo";
bmpFull.alpha = 0;

var bmpContainer:Sprite = new Sprite(); // can receive mouse events, for example:
bmpContainer.addEventListener(MouseEvent.CLICK, clickHandler);
bmpContainer.buttonMode = true; // this just makes it show the hand cursor, and is not necessary for the mouse events to work
bmpContainer.addChild(bmpFull);

, Sprite, , MovieClips , , .

, Bitmap, - , , , Bitmap, . . Sprite .

+7

buttonMode Sprite

MovieClip >> Sprite >> DisplayObjectContainer >> InteractiveObject >> DisplayObject >> EventDispatcher >> Object

                                                            Bitmap >> DisplayObject >> EventDispatcher >> Object
+3

Source: https://habr.com/ru/post/1740591/


All Articles