在 Flash Builder 的自定义组件中,应将自定义代码放在哪里?
在主文件中,我会写:
<components:mybutton id="mybutton1" rollOver="point_rollOverHandler(event)" />
但是,如果我希望组件本身就有这种行为,我应该在 mybutton mxml 文件中的哪里编写它以使其引用自身?
我尝试了
但它抱怨元素类型必须后跟任一属性规范,>或 />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的猜测是您的组件基于 s:Button。只需在组件主 MXML 节点中声明 rollOver 方法,如下所示(第 5 行):
// myButton.mxml
My guess is that your component is based on s:Button. Just declare the rollOver method in your components main MXML node like this (line 5):
// myButton.mxml
在自定义组件的根标记中添加属性 :
然后在自定义组件的脚本标记中创建该函数并设置鼠标事件侦听器:
但这将调用自定义组件中定义的函数 point_rollOverHandler(e:MouseEvent) 。如果您想调用在其父级上定义的函数,那么您拥有的就是最好的方法。否则,您会将组件捆绑得太紧,这将使您的代码变得脆弱并且可重用性降低。
in the root tag for your custom component add the property :
then in the script tag of your custom component create that function and set up the mouse event listener:
but this will call the function point_rollOverHandler(e:MouseEvent) defined in your custom component. If you're looking to call a function defined on it's parent then what you have is the best way. Otherwise you'd be tying the components too tightly together which would make your code brittle and less reusable.