【问题标题】:How to autofill flex input by using JavaScript without flashvars?如何在没有 flashvars 的情况下使用 JavaScript 自动填充弹性输入?
【发布时间】:2011-12-09 13:03:27
【问题描述】:

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

【问题讨论】:

  • 不,在我的情况下它不起作用。我只有 swf 文件,没有源代码。
  • 那恐怕做不到了。
  • Weel,您可以反编译,添加必要的代码并重新编译。但那你要去旅行了。
  • 它是一个真正适用于 flashvars 的 swf 文件吗?

标签: javascript flash apache-flex autofill


【解决方案1】:

您可以写一个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();
    }

}
}

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

【讨论】:

  • 现在有一个创造性的解决方案。 +1
  • 谢谢,但这不是我的方式。于是我意识到我的问题无法解决。
猜你喜欢
  • 1970-01-01
  • 2022-11-22
  • 1970-01-01
  • 1970-01-01
  • 2014-03-31
  • 2021-09-24
  • 2018-11-29
  • 2015-12-02
  • 1970-01-01
相关资源
最近更新 更多