Loading external swf into an Air application

Hi all

I have build an Adobe Air app for desktop PC and have problems to load an external swf. Whenever I try to load, I get:

SecurityError: Error #2070: security sandbox violation... cannot access stage owned by app... blah blah

The file is loading is in a local directory, but I understand its in an another "sandbox" that represents a security risk.


Is there a way to get around this?


Any help would be appreciated


Thank you very much


Matt

That's why I added these comments on domain of the swf file.  for locally loaded SWF files, 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 e-mail of swf file trying to load is stored locally, so I guess that this error is logical. However if I comment on this line, I get the same error "cannot access stage owned by app"?

See below for the 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 void assetPreview() {}

addEventListener(Event.ADDED_TO_STAGE, initialise);

}

public void 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 void viewPreview(e:Event):void

{

addChild (mainSWF);

mainSWF.addChild (loader);

}

}

}

Tags: Adobe Animate

Similar Questions

  • LOAD AN EXTERNAL SWF INTO A CLIP

    Hello.

    I work in a project that load several SWF into a main movie. I use this code and works fine:

    btn_que.addEventListener(MouseEvent.CLICK, presionado); 
    function presionado(Event:MouseEvent){
       //Crea una variable llamda cargador para que cree un cargador//
       var newMedia:Loader = new Loader();
       //Crea una variable para generar un clip vacio (anteriormente host)//
       var cont:MovieClip = new MovieClip();
       //Ruta donde esta la pelicula a cargar//
       newMedia.load(new URLRequest("que_es.swf")); 
       //Posicion X que va a tener//
       cont.x = 0;
       
       stage.addChild(cont);
       cont.addChild(newMedia);
    }

    But I want to load the swf file into a clip (called host), when the person in the button click (really my button is a movi clip).

    What should I do?

    Thank you...

    See the code below (read comments):

    btncerrar.visible = false;
    // declare variable in this scope
    // so that it is visible by other functions
    var newMedia:Loader;
    // container should be in upper score too
    // Sprite is more efficient
    var cont:Sprite;
    
    btn_que.addEventListener(MouseEvent.CLICK, presionado);
    function presionado(Event:MouseEvent){
       //Crea una variable llamda cargador para que cree un cargador//
       newMedia = new Loader();
       //Crea una variable para generar un clip vacio (anteriormente host)//
       cont = new Sprite();
       //Ruta donde esta la pelicula a cargar//
       newMedia.load(new URLRequest("que.swf"));
       btncerrar.visible = true;
       //Posicion X que va a tener//
       cont.x = 0;
       stage.addChild(cont);
       stage.addChild(btncerrar);
       cont.addChild(newMedia);
    
    }
    
    btncerrar.addEventListener(MouseEvent.CLICK, cerrar);
    function cerrar(Event:MouseEvent){
         btncerrar.visible = false;
         cont.removeChild(newMedia);
         newMedia.unload();
         newMedia = null;
    }
    
  • Loading external Swf

    Hi all! I am new to the forum here and relatively new to AS3. I use FlashBuilder code. I'm trying to load a local external .swf into my application. My URLRequest happens not to be able to find the location of the local swf file. I dropped it around with my application, but no matter what I put for the url it does not find the swf file. For example, my swf is game.swf name, but no matter where I put it in the folder of the project and any combination of URL, I can't seem to access. Oddly enough, if it's in the bin-debug and I put URLRequest ("game.swf"), he will find that in the bin-debug, it seems. Please help and thanks in advance!

    In a Flash Builder project you should put it in the folder/src. The bin-debug is generated automatically with whatever you put in / SRC.

    Ideally, you should make a folder under/SRC (so/src/assets) liabilities and then load again URLRequest('assets/game.swf'); Flash Builder copy file /src liabilities more to/bin-debug and your final export file as well.

  • Loading external SWF in as3 SWF Loader style?

    Hello

    I recently did the replacement of as2 as3 and am still struggling to get my head to a particular aspect. I managed to load an external swf into an empty file via the script

    Import LoadDisplayObject;

    var loader: LoadDisplayObject = new LoadDisplayObject ("button_01.swf", true);

    1. loader.addEventListener ("displayObjectLoaded", onComplete, false, 0, true);

    addChild (loader);

    function onComplete(evt:Event):void {}

    trace ("received full load");

    loader.scaleX = loader.scaleY is. 75;

    }

    ... but I'm struggling with the script to make a SWF to load into a space when one of my 3 buttons is activated...

    My page currently has three buttons (button_01, button_02 and button_03) and in a local folder three separate sovereign wealth funds with the same names that I want to load, when you press the appropriate button.

    I managed to get them to load using a tutorial... but what they charge on top of each course... far from ideal. Research on the internet I found a range of different script... goal, that I can't find anywhere that I can find the script to make it work... so why I turned here.

    Any help much appreciated... Thanks in advance.

    Simply call butt1Click (null);

  • Cannot load external swf

    Hello

    Im trying to load an external swf into my project, the code is simply:

    var loader: Loader = new Loader;

    Loader.Load (new URLRequest ("gallery.swf");

    I get an error that says the following when it debug.

    TypeError: Error #1009: cannot access a property or method of a null object reference...
    at gallery_fla::MainTimeline/frame1()
    Cannot view the source code at this location

    I have done this same thing before but never got this error message, I tried to load a swf file that is old and it worked fine.

    IM totally lost here, any help is very appreciated.

    Because the error is pointing Gallery fla, it can be that the problem lies in the SWF Gallery.  What you need to do, is to enter your Setings publish and select the option to enable debugging.  This will help by joining the line number of the code problemed.  You think it's a number of top line to no matter what you have in the file doing the oading that would probably make most issues that's the file you load.

    Just in case you have copied and pasted, the following line should have thrown an error of syntax by lack a parenthesis...

    Loader.Load (new URLRequest ("gallery.swf");

  • Load external swf file

    Hi all

    I am trying to load an external SWF file in my site... but it does not work. Here is my code

    public var CD:Loader = new Loader();

    protected function application1_creationCompleteHandler(event:FlexEvent):void

    {

    CD.load (new URLRequest ("http://localhost/assets/slide.swf"));

    addChild (this. (CD);

    CD.x = 2;

    CD.y = 170;

    / / TODO self-generated stub method

    }

    Can someone tell me what goes wrong...

    The url is correct and his works in my browser when I type " " http://localhost/assets/slide.swf ' in the browser... So the problem is with flex...

    I tried to load this swf into my project and it crashed the browser.  What is written this swf?  AS3 or earlier?  If I'm not mistaken load one previous VERSION other than 3 will cause additional problems and needs to work to spare but I'm not 100% sure.

  • Problem with loading external swf files

    Hello

    I am currently working on a project which is an interactive and dynamic elemtry school presentation to the Denmark. I finished my project and it works perfectly, but only locally on my computer.

    The final draft should be implemented on the site and public work. I tried to implement the project on the site and unfortunately, it does not work as expected.

    When all the files where transferred to the ftp server, only a single files are responding and appear correctly.

    Interactivity of the project is based on a structure of Action script, which is based on the smooth transition between swf files (load another swf file after the action is triggered by clicking on a button) do any work.

    After days of trying to figure out the solution, I'm totally lost. One thing is to publish the project so that all action script will work and answer between swf files, and the other thing is to make it user-friendly for the Android and apple products.

    The presentation is quite heavy because of its loading external swf content files, which are images and movies.

    I really hope you can help me with my problem. I will gladly share the files and codes if it would help solve the problem.

    Best regards

    Agata

    It could be a problem of location of file from loading.  When you place a swf file in an HTML base for targeting anything that the SWF load becomes the folder of the html page.  You may need to adjust the target so that the target of swf files, load it as if it were in the same folder as the html page.

  • Loading a swf into an AS2 clip file

    I had some problems with loading a swf into a clip.  The code I use is as follows

    {We (Release)}
    contentbox.loadMovie("contact.swf",0);
    }

    It works fine on the loading plan, but it loads the swf file so that the upper left corner is at the center of the content area, pushing the bottom and the right side of the way of content off the screen.

    Looks like the contentbox registration mark is centered.

  • How to load external swf files into the AIR

    I try this code its working at the computer, but when I publish this .apk or .ipa file, my external swf file does not open

    (I included my external file as well)

    places_btn.addEventListener (MouseEvent.MOUSE_DOWN, newvid);

    function newvid(event:MouseEvent) {}

    trace ("you clicked me");

    var loadit = new Loader();

    addChild (loadit);

    loadit. Load (new URLRequest ("scene02.swf"));

    }

    01.jpg

    Add this in your newid function:

    You forgot to put the beginning of your original function:

    var loadit = new Loader();

    addChild (loadit);

    var _lc:LoaderContext = new LoaderContext (false null, ApplicationDomain.currentDomain),

    loadit. Load (new URLRequest ("scene02.swf"), _lc);

  • How can I load an external .swf into my step by pressing a button?

    Hello world...

    I have to add an external swf in a specific position in my scene by pushing a button.

    Comeon can help me?

    Thank you.

    using as3, assuming you have a button named "myButton":

    var myLoader:Loader = new Loader(); something to load the swf file

    myButton.addEventListener (MouseEvent.CLICK, loadSWF); Earphone for your button click

    function loadSWF(event:MouseEvent):void {}

    listener for when the charge is complete

    myLoader.contentLoaderInfo.addEventListener (Event.COMPLETE, addSWF);

    load the SWF - using your url of course

    myLoader.load (new URLRequest ("yourSWFsURL.swf"));

    }

    function addSWF(event:Event):void {}

    var mySwf = myLoader.content; the thing charge charger

    mySwf.x = 100; anywhere in x

    mySwf.y = 100; anywhere in there

    addChild (mySwf); Add it to the stage

    }

    HTH,

    -Ted

  • How can I load an external SWF into a clip that is inside another video clip?

    Hello.

    I create my first flash (actionscript 3.0) Web site, but I'm stuck with a visual effect, I want to create.
    I have a window on my website called contentWindow. Whenever you click on a button, this window is supposed to leave the scene, loading the requested content and back on the scene.
    The sliding window is a clip with 83 frames, 21 to enter the stadium, 21 to leave the scene once again, 20 for anything (it's just to simulate the load time) and 21 to the back on the scene.

    Now, my goal is, when the user clicks a navigation button, the window leaves the scene, loading an external SWF with the content and then returned to the scene.

    I have the clip of 'window' with an instance name of "contentWindow". Inside there is an another film clip with an instance name of "contentLoader. The content that the user has requested must appear inside the 'contentLoader.

    Now, when the contentWindow leaves the scene, I get this error message:

    Quote:
    TypeError: Error #1009: cannot access a property or method of a null object reference.
    at rwd_fla::MainTimeline/trigger()
  • Loading the SWF in the AIR for iOS

    Hello

    I'm working on a project in the AIR for iOS.  It's great that we, flash developers are now able to compile our code actionscript for iOS.

    The project that I am working on is divided into different SWF files.  There is a main SWF file that loads the others if necessary.

    Now I can't get a working swf file loading.  The only thing I see is the background of the child being displayed, but then the program freezes and no child actionscript code is exectuted.

    Children SWFs are loaded with a simple charger:

    var loader: Loader = new Loader();

    childLayer.addChild (loader);

    var url: URLRequest = new URLRequest ("child.swf");

    loader.load (url);

    When I post the main swf file I include children swf files in the package.

    Is it really possible to use several swf in your iOS projects?
    And what are the limits for this?

    Thank you.

    greeting,

    Bert

    Yes, it is possible to include any swf in your main application, but your external swf should not contain action script code. Just you can have graphics, symbols, textfield etc on the timeline, but with no timeline script.

  • Load external swf from Web site

    Hi guys,.

    I am trying to load an external swf that is downloaded to a folder on my site from a main swf stored locally.  If I use the standard Loader with URLRequest class it doesn't throw any errors, but nothing comes. I need to change some security in my flash file settings to allow this works?

    Thank you very much

    Matt

    the movieContainer class defined in MasterLibrary.swf AND your main swf file?

    If this isn't the case, you can load MasterLibrary into your currentdomain.  If so, you need to reference the application domain the loader:

    public void loaderIOErrorHandler(e:IOErrorEvent):void / / this function is called when the main movie cannot load a local copy of "MasterLibrary.swf".

    {

    loadLibrary = new Loader();

    loaderAppDomain = new ApplicationDomain();  register if required

    loaderContext = new LoaderContext (false, loaderAppDomain);  register if required

    loadLibrary.contentLoaderInfo.addEventListener (Event.COMPLETE, loaded);

    loadLibrary.load (new URLRequest("myDomain/MasterLibrary.swf"), loaderContext);

    }

    public void loaded(e:Event): void

    {

    var:Class=Class(loaderAppDomain.getDefinition("movieContainer)) C;

    var instance: MovieClip = new C();

    addChild (instance)

    }

  • cannot package animation swf inside the AIR application with API-ad-hoc of the target

    I have included a small animation today in my AIR application using a clip from movie to swf as below

    private var myLoader:Loader = new Loader();  animation connection

    private var url: URLRequest = new URLRequest("..) /.. /.. (' / data / ConnectingAnim.swf ');

    ... code to add the loader and position

    It works fine when I deploy on my device via USB, but when I try to package for ad-hoc distribution, the ipa resulting isn't fair. The screen with the animation is broken.

    I'm guessing that the packaging for the app store is probably broken too.

    Am I missing something?

    Thank you!

    Post edited by: mu.a

    You must use a loader context, unless you use the interpreter mode. Read this article:

    http://help.Adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9 b90204 - 7de0.html

    You want the context.applicationDomain = ApplicationDomain.currentDomain;  variation.

  • Var does not work if I load external swf.

    I have a set with two pages or labeled sections on the main timeline. I have the code for actions happening in each section page / labeled brake. On the first page, there is a VAN specified for each button

    var sourceVar:String;

    Then each button using this var to load a video in FLV player (the player itself is built in the second section of page / labeled).

    function JTV_SatelliteCenterpiece_PlayVideoPopUp(event:MouseEvent): void {}

    sourceVar = "howto_popups/jtvs18w12_LG30.flv";

    gotoAndPlay ("flv_pb");

    }

    where "flv_pb" is the label of the second section of page / labeled. It is on this second page/section labeled a FLVPlayback component named "SWF_flv2", which uses this var

    SWF_flv2.source = sourceVar;

    All above works. My problem is that I decided to take out all the elements (image buttons) in the first section. So, I saved them as an external SWF with all the code in the external swf file.

    Then link the buttons to the section 'flv_pb' in this way:

    function JTV_SatelliteCenterpiece_PlayVideoPopUp(event:MouseEvent): void {}

    MovieClip (parent.parent.parent).sourceVar="howto_popups/jtvs18w07_LG30.flv';

    MovieClip (parent.parent.parent) .gotoAndPlay ("flv_pb");

    }

    The link to the "flv_pb" section works, tells me should be putting up with "MovieClip (parent.parent.parent).".

    However the code as before with the setting up of (being in the external swf file):

    sourceVar = "howto_popups/jtvs18w12_LG30.flv";

    gotoAndPlay ("flv_pb");

    works as well, I don't know why?

    The problem seems to be in the var

    I have an error message 1120: access of undefined property sourceVar

    It is referred to the code in the second page labeled section "flv_pb".

    SWF_flv2.source = sourceVar;

    What are my actions?  I kept the code in the external swf file. Should I move it to the main timeline if possible? Should I reference only the var in the main time line?

    All code must be in the beginning of the time line, rather be broken into sections?

    If you want to use the UILoader component, then its 'content' property is what points to the swf file you load into it.

Maybe you are looking for