如何在 Flex 中管理不规则按钮形状上的鼠标点击

发布于 2024-08-24 04:30:11 字数 260 浏览 2 评论 0原文

在 Flex 中,我尝试设计 3 个与上传的图像类似的按钮 http://www.freeimagehosting.net/uploads/f14d58b49e.jpg

鼠标悬停/单击图像应仅适用于按钮的红色区域。 如何在 Flex 中管理鼠标点击或不规则按钮形状?

谢谢...阿图尔

In Flex, I am trying to design 3 buttons similar to the image uploaded at
http://www.freeimagehosting.net/uploads/f14d58b49e.jpg

The mouse over/click on image should work only on red colored area of the button.
How can I manage the Mouse clicks or Irregular Button shapes in Flex?

Thnx ... Atul

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱的十字路口 2024-08-31 04:30:11

看看这个:flexlib >图像映射。

摘自stackOverflow

Check this out: flexlib > ImageMap.

Taken from stackOverflow

冷夜 2024-08-31 04:30:11

使用基于矢量图形的按钮外观(例如,在 Illustrator 中制作的按钮外观),将每个状态保存为文档中的命名符号,然后导出为 SWF。参考皮肤如下:

.stepButton {
        upSkin: Embed(source="myfile.swf", symbol="StepButton"); 
        downSkin: Embed(source="myfile.swf", symbol="StepButtonDown");
        overSkin: Embed(source="myfile.swf", symbol="StepButtonOver");
        disabledSkin: Embed(source="myfile.swf", symbol="StepButtonDisabled");
}

Flash 会自动从可见部分确定点击区域。这个示例(不称为“myfile.swf”)现在正在应用程序中为我们工作。

Use button skins based on a vector graphic (e.g., one made in Illustrator), save each state as a named symbol in the document, then export as SWF. Reference the skins as follows:

.stepButton {
        upSkin: Embed(source="myfile.swf", symbol="StepButton"); 
        downSkin: Embed(source="myfile.swf", symbol="StepButtonDown");
        overSkin: Embed(source="myfile.swf", symbol="StepButtonOver");
        disabledSkin: Embed(source="myfile.swf", symbol="StepButtonDisabled");
}

Flash will automatically determine the hit area from the visible portion. This example (not called "myfile.swf") is working for us right now in an application.

陌路黄昏 2024-08-31 04:30:11
  1. 通过继承 Canvas 创建 ArrowButtonsHolder 类
  2. 创建 3 个也继承自 Canvas 的子类。例如左箭头按钮、中箭头按钮、右箭头按钮

    公共类LeftArrowButton:Canvas {
    受保护的覆盖函数 updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
    {
    super.updateDisplayList(unscaledWidth, unscaledHeight);

     // 在此处绘制箭头
        // 使用图形来做到这一点 
        图形.beginFill(0xFF0000);
        图形.lineStyle(1, 0x000000);
        图形.moveTo(0, 0);
        图形.lineTo(30, 0);
        图形.lineTo(50, 25);
        图形.lineTo(30, 50);
        图形.lineTo(0, 50);
        图形.lineTo(0, 0);
        图形.endFill();
    }
    

    }

    您还可以创建通用类 ArrowButton 并从该类继承另外 3 个类并重写绘图函数

  3. 通过重写 createChildren():void 方法将此 3 个子按钮对象添加到 ArrowButtonsHolder

    public class ArrowButtonsHolder:Canvas {
    
    // ...
    
    私有变量 leftArrowButton:LeftArrowButton;
    私有变量 middleArrowButton:MiddleArrowButton;
    私有变量 rightArrowButton:RightArrowButton;
    
    // ...
    
    受保护的重写函数 createChildren():void {
        极好的();
    
        // 创建按钮
        左箭头按钮 = new 左箭头按钮();
        中间箭头按钮 = new 左箭头按钮();
        右箭头按钮 = new 左箭头按钮();
    
        // 将它们添加到画布上
        addChild(左箭头按钮);
        addChild(中间箭头按钮);
        addChild(右箭头按钮);
    
        // 通过调整 x, y 来定位这些按钮
        左箭头按钮.x = 0; 
        中间箭头按钮.x = 50; 
        右箭头按钮.x = 100; 
    
        // 分配事件监听器
        leftArrowButton.addEventListener(MouseEvent.CLICK, onLeftArrowButtonClick);
        middleArrowButton.addEventListener(MouseEvent.CLICK, onMiddleArrowButtonClick);
        rightArrowButton.addEventListener(MouseEvent.CLICK, onRightArrowButtonClick);
    }
    
    私人 onLeftArrowButtonClick(事件:MouseEvent):void
    {
        trace("左键单击");
    }
    
    // .. 等等这里实现的另外 2 个方法
    

    }

PS:我的代码中可能存在大量语法错误,但您应该大致了解如何做到这一点

  1. Create ArrowButtonsHolder class by inheriting from Canvas
  2. Create 3 children classes also inherited from Canvas. For example LeftArrowButton, MiddleArrowButton, RightArrowButton

    public class LeftArrowButton:Canvas {
    protected override function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
    {
    super.updateDisplayList(unscaledWidth, unscaledHeight);

        // draw your arrow here
        // use graphics to do it 
        graphics.beginFill(0xFF0000);
        graphics.lineStyle(1, 0x000000);
        graphics.moveTo(0, 0);
        graphics.lineTo(30, 0);
        graphics.lineTo(50, 25);
        graphics.lineTo(30, 50);
        graphics.lineTo(0, 50);
        graphics.lineTo(0, 0);
        graphics.endFill();
    }
    

    }

    You also can create general class ArrowButton and inherit another 3 from that class and override drawing function

  3. Add this 3 child button object to ArrowButtonsHolder by overriding createChildren():void method

    public class ArrowButtonsHolder:Canvas {
    
    // ...
    
    private var leftArrowButton:LeftArrowButton;
    private var middleArrowButton:MiddleArrowButton;
    private var rightArrowButton:RightArrowButton;
    
    // ...
    
    protected override function createChildren():void {
        super();
    
        // create buttons
        leftArrowButton = new LeftArrowButton();
        middleArrowButton = new LeftArrowButton();
        rightArrowButton = new LeftArrowButton();
    
        // add them to canvas
        addChild(leftArrowButton);
        addChild(middleArrowButton);
        addChild(rightArrowButton);
    
        // position these button by adjusting x, y
        leftArrowButton.x = 0; 
        middleArrowButton.x = 50; 
        rightArrowButton.x = 100; 
    
        // assign event listeners
        leftArrowButton.addEventListener(MouseEvent.CLICK, onLeftArrowButtonClick);
        middleArrowButton.addEventListener(MouseEvent.CLICK, onMiddleArrowButtonClick);
        rightArrowButton.addEventListener(MouseEvent.CLICK, onRightArrowButtonClick);
    }
    
    private onLeftArrowButtonClick(event:MouseEvent):void
    {
        trace("Left button clicked");
    }
    
    // .. etc for another 2 methods implemented here
    

    }

PS: There might be tons of syntax mistakes in my code but you should get general idea how to do it

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文