如何在没有 flashvars 的情况下使用 JavaScript 自动填充 Flex 输入?

发布于 2024-12-20 04:46:42 字数 110 浏览 2 评论 0原文

我有 Flex 应用程序(swf 文件)。有谁知道如何在不使用 flashVars 的情况下从 JavaScript 自动填充 flex textInput 吗?它必须在 FireFox 和 IE 中运行。

I have flex application (swf file). Does anyone one know how to autofill flex textInput from JavaScript without using flashVars? It must work in FireFox and IE.

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

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

发布评论

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

评论(1

绿光 2024-12-27 04:46:42

您可以编写一个 wrapper.swf 并将 main.swf 加载到其中。

MyApp.mxml - Flex 项目应用程序文件

<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">
    <s:HGroup id="hGroup" width="100%" height="100%" 
        horizontalAlign="center" verticalAlign="middle">
        <s:TextInput id="textInput" text=""/>
    </s:HGroup>
</s:Application>

Wrapper.as - ActionScript 项目应用程序文件

package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;

import mx.core.mx_internal;

use namespace mx_internal;

public class Wrapper extends Sprite
{

    private var loader:Loader;

    private var application:Object;

    public function Wrapper()
    {
        loader = new Loader();
        addChild(loader);
        loader.contentLoaderInfo.addEventListener(Event.INIT, loader_initHandler);
        loader.load(new URLRequest("MyApp.swf"), 
            new LoaderContext(false, ApplicationDomain.currentDomain));
    }

    private function loader_initHandler(event:Event):void
    {
        addEventListener(Event.ENTER_FRAME, enterFrameHandler);
    }

    private function enterFrameHandler(event:Event):void
    {
        try
        {
            application = ApplicationDomain.currentDomain.getDefinition(
                "mx.core.FlexGlobals").topLevelApplication;
        }
        catch (error:*)
        {
            return; // app is not ready yet
        }
        if (!application)
            return;

        removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
        if (application.initialized)
            injectText();
        else
            application.addEventListener("creationComplete", application_creationCompleteHandler);
    }

    private function injectText():void
    {
        var textInput:Object = application.getElementAt(0).getElementAt(0);
        if (textInput)
            textInput.text = "Custom value";
    }

    private function application_creationCompleteHandler(event:Event):void
    {
        injectText();
    }

}
}

Result

最后,您可以在包装器中添加任何逻辑,包括 ExternalInterface.addCallback

You can write a wrapper.swf and load main.swf into it.

MyApp.mxml - Flex project application file

<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">
    <s:HGroup id="hGroup" width="100%" height="100%" 
        horizontalAlign="center" verticalAlign="middle">
        <s:TextInput id="textInput" text=""/>
    </s:HGroup>
</s:Application>

Wrapper.as - ActionScript project application file

package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;

import mx.core.mx_internal;

use namespace mx_internal;

public class Wrapper extends Sprite
{

    private var loader:Loader;

    private var application:Object;

    public function Wrapper()
    {
        loader = new Loader();
        addChild(loader);
        loader.contentLoaderInfo.addEventListener(Event.INIT, loader_initHandler);
        loader.load(new URLRequest("MyApp.swf"), 
            new LoaderContext(false, ApplicationDomain.currentDomain));
    }

    private function loader_initHandler(event:Event):void
    {
        addEventListener(Event.ENTER_FRAME, enterFrameHandler);
    }

    private function enterFrameHandler(event:Event):void
    {
        try
        {
            application = ApplicationDomain.currentDomain.getDefinition(
                "mx.core.FlexGlobals").topLevelApplication;
        }
        catch (error:*)
        {
            return; // app is not ready yet
        }
        if (!application)
            return;

        removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
        if (application.initialized)
            injectText();
        else
            application.addEventListener("creationComplete", application_creationCompleteHandler);
    }

    private function injectText():void
    {
        var textInput:Object = application.getElementAt(0).getElementAt(0);
        if (textInput)
            textInput.text = "Custom value";
    }

    private function application_creationCompleteHandler(event:Event):void
    {
        injectText();
    }

}
}

Result

Finally, you can add any logic in wrapper including ExternalInterface.addCallback.

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