如何在flex4/MXML/Spark中从外部文件包含动作脚本功能? [英] How to include an actionscript function from an external file in flex4/MXML/Spark?

查看:90
本文介绍了如何在flex4/MXML/Spark中从外部文件包含动作脚本功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

事实证明,无法在嵌入式<fx:Script><![CDATA[中声明类,因此我需要将actionscript代码放入并包含在外部Sourcefile中.错误已被注释掉

It turns out that’s it’s impossible to declare a class inside a embedded <fx:Script><![CDATA[ so it turns I need to put and include the actionscript code inside an external Sourcefile. The error is commented out

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="1955" minHeight="1600">
    <fx:Script source="URLRequest.as" />
    <s:layout>
        <s:BasicLayout />
    </s:layout>
    <s:Panel x="0" y="0" width="955" height="600" title="Bypass">
        <s:layout>
            <s:BasicLayout />
        </s:layout>
        <s:Label x="1" y="1" text="Please enter the ɢɪᴛ repository ʜᴛᴛᴘ ᴜʀʟ :"/>
        <s:TextInput x="224" y="1" width="726" id="txtName" text="http://ytrezq.sdfeu.org/flashredirect/?http"/>
        <s:Button x="1" y="12" label="ɢɪᴛ push !" click="send()"/> <!-- Undefined Method method error -->
    </s:Panel>
    <fx:Declarations>
    </fx:Declarations>
</s:Application>

并在URLRequest.as中:

and in URLRequest.as :

final public class MyClass {
    // some stuff
}
public function send():void {
    var request:Myclass=new Myclass(txtName.text);
    // Some stuff with 
}

所以问题很简单,但是我找不到任何答案.至少没有用于带有Spark的mxml.
send()不必在班级中,您可以看到它不在班级中.但是它需要使用一个自定义类.

So the question is simple but I couldn’t found the answer anywhere. At least not with for mxml with Spark.
send() doesn’t need to be in a class and as you can see is outside a class. But it needs to use a custom class.

那么如何从URLRequest.as调用send()?

So how can I call send() from URLRequest.as ?

推荐答案

现在,我终于了解了您想要做什么,我有了另一个想法-有点复杂.

Now that I finally understand what you want to do, I've another idea - which is a little more complicated.

创建一个名为 Dummy.as 的文件,并使用以下文件填充该文件:

Create a file called Dummy.as and fill it with this:

package
{
    public class Dummy
    {
        public static function send(url:String):void
        {
            var request:Myclass=new Myclass(url);
        }
    }
}
class Myclass
{
    public function Myclass(inp:String)
    {
        trace(inp);
    }
}

再次,摆脱

<fx:Script source="URLRequest.as" />

并替换为

<fx:Script>
    <![CDATA[
        import Dummy;
    ]]>
</fx:Script>

最后替换

<s:Button x="1" y="12" label="ɢɪᴛ push !" click="send()"/>

使用

<s:Button x="1" y="12" label="ɢɪᴛ push !" click="Dummy.send(txtName.text)"/>

这里的窍门是,我们导入的Dummy类只有一个静态函数,我们可以在不实例化的情况下调用它. 此外-只要在包之外定义它,我们就可以添加更多的类定义,这些定义对于Dummy类是可见的.

The trick here is that we're importing the Dummy class that just has a static function which we can call without instantiating. Furthermore - as long as we define it outside of the package, we can add more class definitions, which are visible to the Dummy class.

这篇关于如何在flex4/MXML/Spark中从外部文件包含动作脚本功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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