Highlighted

Load remote swf and access to stage

New Here ,
May 17, 2018

Copy link to clipboard

Copied

Hi,

I'm building a simple AIR app to load a remote swf.

If I load the swf in any browser with Flash installed the app is working as expected.

But if I create a AIR app that uses SWFLoader I get an error :

SecurityError: Error #2070: Security sandbox violation: caller https://localhost:5015/Container.swf cannot access Stage owned by app:/FlexLoader.swf.

  at flash.display::Stage/get stageWidth()

I guess this is because the loaded swf is not allowed to access the Stage, so I tried to set the securityDomain of the LoaderContext to SecurityDomain.currentDomain

but I get:

SecurityError: Error #2142: Security sandbox violation: local SWF files cannot use the LoaderContext.securityDomain property. app:/FlexLoader.swf

Is there a way to grant access to the Stage (and probably other stuff) to the loaded SWF ?

<?xml version="1.0" encoding="utf-8"?>

<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"

  layout="absolute"

  initialize="init()">

  <mx:Script>

  function init() {

  import flash.system.SecurityDomain;

  import flash.system.ApplicationDomain;

  /*

  Security.allowDomain("*");

  Security.allowInsecureDomain("*");

  */

  var context:LoaderContext = new LoaderContext();

  //context.securityDomain = SecurityDomain.currentDomain;

  context.allowLoadBytesCodeExecution = true;

  context.applicationDomain = new ApplicationDomain();

  contentLoader.loaderContext = context;               

  contentLoader.source = "https://localhost:5015/ndsconsole/Container.swf";

  }

  </mx:Script>

<mx:SWFLoader id="contentLoader" trustContent="true" height="100%" width="100%"/>

</mx:WindowedApplication>

Thanks in advance.

Regards.

PS: This is my first post on this forum, let me know if it's not the appropriate one for my question

TOPICS
Development

Views

827

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Load remote swf and access to stage

New Here ,
May 17, 2018

Copy link to clipboard

Copied

Hi,

I'm building a simple AIR app to load a remote swf.

If I load the swf in any browser with Flash installed the app is working as expected.

But if I create a AIR app that uses SWFLoader I get an error :

SecurityError: Error #2070: Security sandbox violation: caller https://localhost:5015/Container.swf cannot access Stage owned by app:/FlexLoader.swf.

  at flash.display::Stage/get stageWidth()

I guess this is because the loaded swf is not allowed to access the Stage, so I tried to set the securityDomain of the LoaderContext to SecurityDomain.currentDomain

but I get:

SecurityError: Error #2142: Security sandbox violation: local SWF files cannot use the LoaderContext.securityDomain property. app:/FlexLoader.swf

Is there a way to grant access to the Stage (and probably other stuff) to the loaded SWF ?

<?xml version="1.0" encoding="utf-8"?>

<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"

  layout="absolute"

  initialize="init()">

  <mx:Script>

  function init() {

  import flash.system.SecurityDomain;

  import flash.system.ApplicationDomain;

  /*

  Security.allowDomain("*");

  Security.allowInsecureDomain("*");

  */

  var context:LoaderContext = new LoaderContext();

  //context.securityDomain = SecurityDomain.currentDomain;

  context.allowLoadBytesCodeExecution = true;

  context.applicationDomain = new ApplicationDomain();

  contentLoader.loaderContext = context;               

  contentLoader.source = "https://localhost:5015/ndsconsole/Container.swf";

  }

  </mx:Script>

<mx:SWFLoader id="contentLoader" trustContent="true" height="100%" width="100%"/>

</mx:WindowedApplication>

Thanks in advance.

Regards.

PS: This is my first post on this forum, let me know if it's not the appropriate one for my question

TOPICS
Development

Views

828

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 17, 2018 0
Engaged ,
May 17, 2018

Copy link to clipboard

Copied

Instead of new ApplicationDomain(), for AIR apps you need to reference the app's current application domain like this:

context.applicationDomain = ApplicationDomain.currentDomain;

Since you mentioned accessing the stage, just wanted to also make sure you were aware that remote SWFs can't run any ActionScript in apps on iOS.  There are some packaging workarounds if you're loading local external SWFs and need to use ActionScript, but as far as I know remote SWFs still aren't allowed to use any ActionScript byte code.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 17, 2018 0
New Here ,
May 17, 2018

Copy link to clipboard

Copied

Hi,

thanks for answering.

I tried to change to:

context.applicationDomain = ApplicationDomain.currentDomain;

But I still get the same error:

SecurityError: Error #2070: Security sandbox violation: caller https://localhost:5015/Container.swf cannot access Stage owned by app:/FlexLoader.swf.

I'm using AIR for building a Desktop app.

Basically I just want to wrap the swf inside a AIR app I can distribute and avoid needing the browser.

The same swf loaded in the browser works as expected, the problem is when loading it inside my AIR app.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 17, 2018 0
New Here ,
May 22, 2018

Copy link to clipboard

Copied

Hi,

You need to change

context.allowLoadBytesCodeExecution = true;

to

context.allowCodeImport = true;

I am doing the same as you (building an SWF viewer in Air) and it works, but I still can't access the stage (TypeError: Error #1009). In my case I have thus far been able to work around that, we create the SWF's ourselves.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 22, 2018 0
New Here ,
May 23, 2018

Copy link to clipboard

Copied

Hello,

thanks for answering, I'll try that.

Let me know if you manage to access the stage, ideally I cannot change the imported swf.

In my case I ended up using the mx:HTML component and created a simple app like this:

<?xml version="1.0"?>
<s:WindowedApplication 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="1280" minHeight="800">
  <mx:HTML id="html" location="http://localhost:5015/Container.swf" height="100%" width="100%"/>
</s:WindowedApplication>

With this I don't have any problem with the stage access but in the end is like using AIR as a browser with Flash support.

There's another issue with this approach but I don't want to go off-topic, the problem I'm seeing is that the rendering is not high resolution and texts look pixelated, I have another post for this in case interested: https://forums.adobe.com/thread/2493800

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 23, 2018 0