如何将Click事件侦听器分配给Flex 4中的绘制路径

时间:2013-04-16 02:16:29

标签: actionscript-3 flex path flex4 flex4.5

我在mxml中有一个火花路径:

<s:Group id="group" click="clickHandler(event)" >
                <s:Path id="na259" x="385.301" y="140.422" winding="nonZero"   data="M2.01562 0.141602 2.32812 0.110352 2.78125 0.0322266 3.15625 0.0322266 3.59375 0 4.04688 0 4.5625 0.0322266 5.04688 0 5.59375 0 5.95312 0.0166016 6.39062 0.0166016 6.875 0.0478516 7.29688 0.0712891 7.76807 0.0712891 8.29688 0.0947266 8.78125 0.141602
                        9.28125 0.141602 9.6875 0.188477 10.0469 0.219727 10.5625 0.282227 11 0.313477 11.4062 0.360352C11.4062 0.360352 11.7969 0.422852 11.8438 0.438477 11.8906 0.454102 12.3281 0.547852 12.3281 0.547852L12.8281 0.641602 13.3125 0.782227 13.6562 0.860352
                        14.0312 0.985352 14.3906 1.1416 14.7031 1.28223 15.0781 1.43848 15.3594 1.68848 15.6719 1.98535 15.9062 2.29785 16.1875 2.79785 16.25 3.46973 16.1875 4.09473 16.125 4.6416 15.9375 5.17285 15.6875 5.79785 15.3906 6.25098 15.0469 6.73535 14.5938
                        7.15723 14.125 7.42285 13.6719 7.5791 13.208 7.5791 12.5938 7.3291 11.9844 6.90723 11.4062 6.53223 11.0625 6.29785 10.7188 6.03223 10.3438 5.93848 9.96875 6.11035 9.70312 6.37598 9.57812 6.81348 8.3125 7.04785 7.79688 6.92285 7.45312 6.7666 6.98438
                        6.67285 6.23438 6.61035 5.84375 6.6416 5.70312 6.6416 5.53125 6.67285 5.45312 6.8291 5.07812 6.65723 4.6875 6.54785 4.26562 6.48535 3.79688 6.53223 3.3125 6.65723 2.89062 6.98535 2.57812 7.23535 2.22607 7.5791 1.9375 7.8291 1.73438 8.12598 1.39062
                        8.2666 1.03125 8.12598 0.65625 7.8291 0.59375 7.5166 0.4375 7.1416 0.328125 6.68848 0.296875 6.15723 0.234375 5.7041 0.234375 5.23535 0.3125 4.65723 0.234375 4.2627 0.15625 3.84473 0.046875 3.15723 0 2.61035 0.03125 2.04785 0.078125 1.67285 0.21875
                        1.37598 0.46875 1.12598 0.734375 0.766602 1.01562 0.469727 1.39062 0.266602 2.01562 0.141602Z">
                    <s:stroke>
                        <s:SolidColorStroke weight="0.25" caps="none" joints="miter" miterLimit="10"/>
                    </s:stroke>
                </s:Path>
            </s:Group>

所以,我的问题是,我需要精确地使这条路径可以点击......而不是周围的群体...... 该组是一个盒子,所以它不够精确。

此标记:

<s:Path>

bot是否接受属性“click”,因此我无法为此标记创建click事件侦听器。

2 个答案:

答案 0 :(得分:3)

将您的路径包装到一个组中,并将该组的mouseEnabledWhereTransparent属性设置为false。

答案 1 :(得分:0)

通过使用Rect组件(例如

),它会有所帮助
<!-- hit area -->
<s:Rect left="0" right="0" top="0" bottom="0">
    <s:fill>
        <s:SolidColor color="#000000" alpha="0"/>
    </s:fill>
</s:Rect>


<s:Group id="group" click="clickHandler(event)" >
                <s:Path id="na259" x="385.301" y="140.422" winding="nonZero"   data="M2.01562 0.141602 2.32812 0.110352 2.78125 0.0322266 3.15625 0.0322266 3.59375 0 4.04688 0 4.5625 0.0322266 5.04688 0 5.59375 0 5.95312 0.0166016 6.39062 0.0166016 6.875 0.0478516 7.29688 0.0712891 7.76807 0.0712891 8.29688 0.0947266 8.78125 0.141602
                        9.28125 0.141602 9.6875 0.188477 10.0469 0.219727 10.5625 0.282227 11 0.313477 11.4062 0.360352C11.4062 0.360352 11.7969 0.422852 11.8438 0.438477 11.8906 0.454102 12.3281 0.547852 12.3281 0.547852L12.8281 0.641602 13.3125 0.782227 13.6562 0.860352
                        14.0312 0.985352 14.3906 1.1416 14.7031 1.28223 15.0781 1.43848 15.3594 1.68848 15.6719 1.98535 15.9062 2.29785 16.1875 2.79785 16.25 3.46973 16.1875 4.09473 16.125 4.6416 15.9375 5.17285 15.6875 5.79785 15.3906 6.25098 15.0469 6.73535 14.5938
                        7.15723 14.125 7.42285 13.6719 7.5791 13.208 7.5791 12.5938 7.3291 11.9844 6.90723 11.4062 6.53223 11.0625 6.29785 10.7188 6.03223 10.3438 5.93848 9.96875 6.11035 9.70312 6.37598 9.57812 6.81348 8.3125 7.04785 7.79688 6.92285 7.45312 6.7666 6.98438
                        6.67285 6.23438 6.61035 5.84375 6.6416 5.70312 6.6416 5.53125 6.67285 5.45312 6.8291 5.07812 6.65723 4.6875 6.54785 4.26562 6.48535 3.79688 6.53223 3.3125 6.65723 2.89062 6.98535 2.57812 7.23535 2.22607 7.5791 1.9375 7.8291 1.73438 8.12598 1.39062
                        8.2666 1.03125 8.12598 0.65625 7.8291 0.59375 7.5166 0.4375 7.1416 0.328125 6.68848 0.296875 6.15723 0.234375 5.7041 0.234375 5.23535 0.3125 4.65723 0.234375 4.2627 0.15625 3.84473 0.046875 3.15723 0 2.61035 0.03125 2.04785 0.078125 1.67285 0.21875
                        1.37598 0.46875 1.12598 0.734375 0.766602 1.01562 0.469727 1.39062 0.266602 2.01562 0.141602Z">
                    <s:stroke>
                        <s:SolidColorStroke weight="0.25" caps="none" joints="miter" miterLimit="10"/>
                    </s:stroke>
                </s:Path>
            </s:Group>