Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Loading external swf into Air App

New Here ,
May 13, 2014 May 13, 2014

Hi All,

I'm building an Adobe Air App for desktop and am having problems loading an external swf. Every time i try to load i get:

SecurityError: Error #2070: Security sandbox violation........ cannot access Stage owned by app....blah blah

The file that is being loaded is in a local directory, but as i understand its in a different 'sandbox' which is a security risk.


Is there any way around this?!


Any help would be much appreciated


Many Thanks


Matt

TOPICS
ActionScript
4.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 14, 2014 May 14, 2014

that's why i added those comments about the swf's domain.  for locally loaded swfs, use:

SFMltd wrote:

Hi Kglad, Thanks for the Example.

if i run my class with securityDomain = SecurityDomain.currentDomain; then it throws this error: SecurityError: Error #2142: Security sandbox violation: local SWF files cannot use the LoaderContext.securityDomain property.

The swf file im trying to load is stored locally so i guess this error makes sense. However if i comment out that line i get the same "ca

...
Translate
Community Expert ,
May 13, 2014 May 13, 2014

you're using a loadercontext, correct?  is it using currentDomain?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 13, 2014 May 13, 2014

Hi Kglad,

I have tried using a loaderContext with currentDomain but I couldn't get it to work. Could you give me an example of the correct approach? Perhaps I was using it wrongly with the loader instance.

Many Thanks

Matt

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 13, 2014 May 13, 2014

var loaderContext=new LoaderContext(true,ApplicationDomain.currentDomain);  //<-if you're loading a swf from a different domain, load policy file.  ie, you need a policy file on the loaded swf's server

loaderContext.securityDomain=securityDomain.currentDomain;  // "  ".

var loader:Loader=new Loader();

loader.load(new URLRequest('yourswf.swf',loaderContext);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 14, 2014 May 14, 2014

Hi Kglad, Thanks for the Example.

if i run my class with securityDomain = SecurityDomain.currentDomain; then it throws this error: SecurityError: Error #2142: Security sandbox violation: local SWF files cannot use the LoaderContext.securityDomain property.

The swf file im trying to load is stored locally so i guess this error makes sense. However if i comment out that line i get the same "cannot access Stage owned by app" error?

See below for class:

package  {

  import flash.display.MovieClip;

  import flash.filesystem.File;

  import flash.events.Event;

  import flash.net.FileReference;

  import flash.events.MouseEvent;

  import flash.display.Loader;

  import flash.net.URLRequest;

  import flash.system.LoaderContext;

  import flash.system.ApplicationDomain;

  import flash.system.SecurityDomain;

  public class assetPreview extends MovieClip {

  private var loader:Loader;

  private var mainSWF:MovieClip = new MovieClip();

  public function assetPreview() {

  addEventListener(Event.ADDED_TO_STAGE, initialise);

  }

  public function initialise(e:Event):void

  {

  removeEventListener(Event.ADDED_TO_STAGE, initialise);

  var allowSWF:LoaderContext = new LoaderContext(true,ApplicationDomain.currentDomain);

  allowSWF.securityDomain = SecurityDomain.currentDomain;

  loader = new Loader();

  loader.load( new URLRequest(settingsXML.pathToSWF),allowSWF);

  loader.contentLoaderInfo.addEventListener(Event.COMPLETE, viewPreview);

  }

  public function viewPreview(e:Event):void

  {

  addChild(mainSWF);

  mainSWF.addChild(loader);

  }

  }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 14, 2014 May 14, 2014

that's why i added those comments about the swf's domain.  for locally loaded swfs, use:

SFMltd wrote:

Hi Kglad, Thanks for the Example.

if i run my class with securityDomain = SecurityDomain.currentDomain; then it throws this error: SecurityError: Error #2142: Security sandbox violation: local SWF files cannot use the LoaderContext.securityDomain property.

The swf file im trying to load is stored locally so i guess this error makes sense. However if i comment out that line i get the same "cannot access Stage owned by app" error?

See below for class:

package  {

  import flash.display.MovieClip;

  import flash.filesystem.File;

  import flash.events.Event;

  import flash.net.FileReference;

  import flash.events.MouseEvent;

  import flash.display.Loader;

  import flash.net.URLRequest;

  import flash.system.LoaderContext;

  import flash.system.ApplicationDomain;

  import flash.system.SecurityDomain;

  public class assetPreview extends MovieClip {

  private var loader:Loader;

  private var mainSWF:MovieClip = new MovieClip();

  public function assetPreview() {

  addEventListener(Event.ADDED_TO_STAGE, initialise);

  }

  public function initialise(e:Event):void

  {

  removeEventListener(Event.ADDED_TO_STAGE, initialise);

  var allowSWF:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain);

// allowSWF.securityDomain = SecurityDomain.currentDomain;

  loader = new Loader();

  loader.load( new URLRequest(settingsXML.pathToSWF),allowSWF);

  loader.contentLoaderInfo.addEventListener(Event.COMPLETE, viewPreview);

  }

  public function viewPreview(e:Event):void

  {

  addChild(mainSWF);

  mainSWF.addChild(loader);

  }

  }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 16, 2014 May 16, 2014

Thanks for your help Kglad, got it working now.

Cheers

Matt

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 16, 2014 May 16, 2014
LATEST

you're welcome.

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