如何在同一个 mxml 中从一个脚本访问另一个脚本的函数 [英] How to access Function from one script to another script in same mxml

查看:30
本文介绍了如何在同一个 mxml 中从一个脚本访问另一个脚本的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是 my.mxml 中的一个脚本

this is one script in my.mxml

  <fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
        public function __changeSel():void{

        }
    ]]>
  </fx:Script>

在同一个 my.mxml 中的组件标签中的另一个脚本

another script in component tag in same my.mxml

<fx:Component>
                                        <s:ComboBox change="changeSel(event)">  
                                            <s:id>selID</s:id>
                                            <s:dataProvider>
                                                    <s:ArrayCollection>
                                                        <fx:String>Less Than</fx:String>
                                                    </s:ArrayCollection>                                                    
                                            </s:dataProvider>
                                            <fx:Script>
                                                <![CDATA[
                                                    public function changeSel(even:Event):void{
                                                         __changeSel();
                                                    }
                                                ]]>
                                            </fx:Script>
                                        </s:ComboBox>
                                    </fx:Component>             

但是当我调用 __changeSel();它不承认这个功能.有什么办法可以解决这个问题.

But when i call __changeSel(); it dose not recognize this function. is there any way to get this thing fixed.

推荐答案

你不应该使用内联组件.这导致范围转移.编写一个适当的 self contains component 并在显示列表上调度事件,这样复合根就可以在冒泡事件上设置一个监听器.

You should not use inline components. That leads to a scope shift. Write a proper self contains component and dispatch events over the display list, so the composites root can set a listener on the bubbling events.

否则尝试在内联渲染器中使用outerDocument来调用该方法.

Otherwise try to use outerDocument in the inline renderer to invoke the method.

这篇关于如何在同一个 mxml 中从一个脚本访问另一个脚本的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆