【问题标题】:Flash / AS3 - Works in IDE But Strange Browser Behavior. Why?Flash / AS3 - 在 IDE 中工作但奇怪的浏览器行为。为什么?
【发布时间】:2015-09-29 07:38:00
【问题描述】:

好的,我有一个使用 Loader 对象在子 swf 中加载的 Flash 浏览器应用程序。我认为向 Loader 对象添加鼠标单击侦听器可以让我侦听对象上的点击,但事实并非如此。 :/

我确实看到了点击!!!当我在我的 IDE (Flash Develop) 中进行测试时被追踪。但是,当放入任何浏览器时,鼠标处理程序永远不会被调用。有谁知道为什么会发生这种情况?

此外,尝试访问加载器对象的子对象会导致安全沙箱错误。

public function Main() 
    {
        trace("Starting...");
        Security.allowDomain('*');
        Security.allowInsecureDomain('*');

        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        // entry point


        var inputFlashVars:Object = this.loaderInfo.parameters

        _swfLoader = new Loader();
        stage.addChild(_swfLoader);
        _swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSwfLoaded);


        var ldrContext:LoaderContext = new LoaderContext(true);
        ldrContext.checkPolicyFile = true;
        ldrContext.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
        //ldrContext.applicationDomain = new ApplicationDomain(new ApplicationDomain());

        var urlForVideoToPlay:String = AD_SWF_URL;
        trace("Loading swf: " + urlForVideoToPlay + " with click URL: " + CLICKTHROUGH_URL);

        _swfLoader.load(new URLRequest(urlForVideoToPlay), ldrContext);

    }


    private function onSwfLoaded(e:Event):void 
    {

        //var swfChild:* = _swfLoader.getChildAt(0);
        //_swfLoader.mouseChildren = false;
        trace(e.target);

        _swfLoader.stage.addEventListener(MouseEvent.CLICK, onInnerSwfClicked, false);
        _swfLoader.stage.addEventListener(MouseEvent.MOUSE_DOWN, onInnerSwfClicked, false);
        _swfLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onSwfLoaded);
        trace("Ad swf loaded!");
    }

    private function onInnerSwfClicked(e:Event):void 
    {
        trace("clicked!!!");

        e.stopImmediatePropagation();

    }

【问题讨论】:

    标签: flash actionscript-3


    【解决方案1】:

    我认为错误来自您的点击侦听器,您将它们附加到错误的舞台对象:

    _swfLoader.stage.addEventListener(MouseEvent.CLICK, onInnerSwfClicked, false);
    _swfLoader.stage.addEventListener(MouseEvent.MOUSE_DOWN, onInnerSwfClicked, false);
    

    当您在父 swif 中加载子 swif 时,舞台指向父 swif。它可以在调试模式下工作,因为您正在加载没有外壳/父级的子 swif。

    试试这个:

    _swfLoader.content.addEventListener(MouseEvent.CLICK, onInnerSwfClicked, false);
    _swfLoader.content.addEventListener(MouseEvent.MOUSE_DOWN, onInnerSwfClicked, false);
    

    【讨论】:

    • 输入 _swfLoader.content 会导致安全错误:SecurityError:错误 #2121:安全沙箱违规:Loader.content:127.0.0.1/thisSwfswf 无法访问 s0.2mdn.net/2644440/300x250_eas_display_campaign_v2.swf。这可以通过调用 Security.allowDomain 来解决。在 flash.display::Loader/get content()
    • 并且您需要确保您的 crossdomain.xml 策略正常
    • 我的 swf 的跨域做加载或托管子 swf 的服务器的跨域?
    • 父 Swf 服务器需要允许来自托管子 swf 的服务器的请求
    • @Robuttst,您自己的 SWF 文件是否在某个 HTTPS 服务器中?您正在加载的其他 SWf 位于 https: //s0.2mdn.net 等,因此这意味着您不能只从您自己的常规 http: //mysite访问其数据> 但如果从您的安全 httpS: //mysite 加载,您可以这样做。您的网站上没有“安全”的挂锁图标意味着没有加载其他 HTTPS 服务器数据..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-23
    • 1970-01-01
    • 2013-09-16
    相关资源
    最近更新 更多