开发者

Flash: making an interactable image

开发者 https://www.devze.com 2023-02-10 23:37 出处:网络
Im trying to figure out how to take an image and make it interactable in different parts. The image is a bunch of arrows that make a circle, and, what I want to happen is 开发者_运维知识库when a parti

Im trying to figure out how to take an image and make it interactable in different parts. The image is a bunch of arrows that make a circle, and, what I want to happen is 开发者_运维知识库when a particular arrow is hovered over it enlarges the arrows and hovers over the two adjacent arrows.

I imported the image from illustrator to flash onto a single frame and made each arrow a button, with the down image an enlarged version, but it appears that the images are on separate layers somehow? when I go to hover over one of the arrows, it is under one arrow but over another.

How would I get the hovered over arrow to be always on top of all of the other images in the movie?

Maybe a code that, onHover brought the symbol to the front of the stage?


I'm not 100% sure about the structure of you flash app/movie but I think you would do something along the line of the following:

import flash.display.Sprite;
import flash.events.MouseEvent;

arrow.addEventListener(MouseEvent.MOUSE_OVER, onArrowMouseOver);
arrow.addEventListener(MouseEvent.MOUSE_OUT, onArrowMouseOut);

function onArrowMouseOver(e:MouseEvent):void
{
    var arrow:Sprite = Sprite(e.target);
    setChildIndex(arrow, this.numChildren-1);
    arrow.scaleX = arrow.scaleY = 2;
}

function onArrowMouseOut(e:MouseEvent):void
{
    var arrow:Sprite = Sprite(e.target);
    arrow.scaleX = arrow.scaleY = 1;
}


You can attach an event listener function to react on MouseEvent.MOUSE_OVER, which will bring the button to front.

Create MyButton.as (code below) to hold a class that extends SimpleButton and add the listener function there. Then set MyButton as base class for the arrow symbol in the properties panel.

package {

    import flash.display.SimpleButton;
    import flash.events.MouseEvent;

    public class MyButton extends SimpleButton {
        private function onMouseOver ( ev:MouseEvent ) : void {
            parent.setChildIndex (this, parent.numChildren -1);
        }

        public function MyButton () {
            addEventListener (MouseEvent.MOUSE_OVER, onMouseOver);
        }
    }
}
0

精彩评论

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