Accessing AIR API from loaded SWFs

I am relatively new to AIR development and I can't get my head a round a little issue. I have an AIR application created in Flash CS5 that is just a shell that loads modules on demand, those modules are just SWF.
I would like to access the AIR API directly from the classes of those SWF but of course they don't compile because in the publish settings they are just exported for Flash player 10 and don't see the AIR API. I tried adding airglobal.swc to the library hoping it would sort out the compiling problem but it doesn't and it generates many errors.
I use to develop with MDM ZInc and I would just import the MDM SWC in any classes that would want access the MDM API, I am unsure how to proceed with AIR.
Any help would be appreciated.
Calwen

Hi Calwen,
here is basic sample how you could achieve that. Note: I'm using mxml syntax and components - but the *KEY* is api use of LoaderContext - not what real components are used to model UI.
Say I have host:
<?xml version="1.0" encoding="utf-8"?>
<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"
                            creationComplete="creationCompleteHandler(event)">
     <fx:Script>
          <![CDATA[
               import mx.events.FlexEvent;
               protected function creationCompleteHandler(event:FlexEvent):void
                    var loaderContext:LoaderContext = new LoaderContext();
                    loaderContext.allowCodeImport = true;
                    swfLoader.loaderContext = loaderContext;
                    swfLoader.load("app:/MyLoadedApp.swf");
          ]]>
     </fx:Script>
     <s:SWFLoader id="swfLoader" width="100%" height="100%"/>
</s:WindowedApplication>
MyLoadedApp is not created with air SDK at all - it is just flash.display.Sprite movie clip created with any compatible Flash compiler:
package
     import flash.display.Sprite;
     import flash.events.*;
     import flash.text.TextField;
     import flash.utils.getDefinitionByName;
     public class MyLoadedApp extends Sprite
          public function MyLoadedApp()
               addEventListener(Event.ADDED_TO_STAGE, initApp);
          protected function initApp(addedToStageEvent:Event):void
               removeEventListener(Event.ADDED_TO_STAGE, initApp);
               var clazz:Class = flash.utils.getDefinitionByName("flash.filesystem.File") as Class;
               if(clazz)
                    // we could read documents directory (File.documentsDirectory) using class access
                    var directory:Object = clazz.documentsDirectory;
                    try
                         // and we could show browse dialog (now we are using instance - not class)
                         directory.addEventListener(Event.SELECT, directorySelectedHandler);
                         directory.browseForDirectory("Please select directory");
                    } catch (error:Error)
                         // handle error
                         var errorText:TextField = new TextField();
                         errorText.autoSize = "left";
                         errorText.text = error.message;
                         addChild(errorText);
          protected function directorySelectedHandler(selectEvent:Event):void
               var directory:Object = selectEvent.target;
               var files:Array = directory.getDirectoryListing();
               var resultsTextField:TextField = new TextField();
               resultsTextField.autoSize = "left";
               resultsTextField.multiline = true;
               resultsTextField.appendText(selectEvent.type+":\n");
               for(var i:uint = 0; i < files.length; i++)
                    resultsTextField.appendText(files[i].name+"\n");
               addChild(resultsTextField);
This is not safe at all and loaded module can do everything I think (we talk about local modules from app storage, like in Zinc, right?)
kind regards,
Peter

Similar Messages

  • (how) can I access Java APIs from web-page-hosted JavaScript?

    Can I access Java APIs from a web-page via JavaScript if I have a JRE installed on the client machine? And if so, how?
    Thanks in advance for your time and consideration.

    John L. wrote:
    Can I access Java APIs from a web-page via JavaScript if I have a JRE installed on the client machine? And if so, how?As far as I can remember that was actually possible in the very first versions of Netscape because Netscape really wanted to pretend Javascript and Java were meant to be used together. But they soon removed that functionality. Can you guess why?
    Because people were using the File/IO classes to easily steal or remove files on the harddrive, among other such niceties. You do NOT want to have such control from a web application. People will abuse it.

  • AIR crashes on loading swf with 'Imported for runtime sharing' fonts

    Hello everybody,
    I have a trouble with an AIR application developped with Flex but the error seems to come from the Flash/AIR, after some searches a staff member (Flex harUI) said me that I could find more help for my trouble here.
    I'm developping an AIR application which loads an external swf. This swf contains 'Imported for runtime sharing' fonts from another swf to reduce its size.
    When the AIR application has finished to load (see message below) the whole application crashes without giving any error message except the usual "Process terminated unexpectedly" error message.
    End Loading: [SWF] C:\Users\dev02\myProject\index.swf - 83,930 bytes after decompression
    Error Message:
    Process terminated unexpectedly.
    Launch command details:  "C:\Program Files (x86)\Adobe\Adobe Flash Builder 4\sdks\4.6.0\bin\adl.exe" -runtime "C:\Program Files (x86)\Adobe\Adobe Flash Builder 4\sdks\4.6.0\runtimes\air\win" "C:\Users\dev02\Adobe Flash Builder 4\Languages_Editor\bin-debug\Language_Editor-app.xml" "C:\Users\dev02\Adobe Flash Builder 4\Languages_Editor\bin-debug"
    I use Flash Builder 4 (build 272416) with sdk 4.6.
    Full discussion here.
    I tried to load the external swf with the most basics codes, it works with a Flash web app but not with a Flex/AIR app or a Flash/AIR app.
    Thanks for the help !

    Thanks for the anwser.
    In fact, I cannot specify a swc because my main application is an editor of sub-applications where each one has its own library.
    The bug remains when sharing a simple MovieClip too.
    Maybe, if I explain my project it will be a little more clear.
    I'm developping a multi-languages module / application.
    For each module, I have an external xml for texts. So in order to add a new language we don't need to recompile, just to change texts in the xml. But, I had to externalize my fonts, (imagine if each swf contains the whole characters set like latin, cyrillic, etc.).
    And then, I have my main text editor application above the module, which loads texts xmls and a preview of the page where we need to change the text. (This is where it crashes, during the process of loading the preview).
    My editor works great for translating, changing texts, modify images but without the preview, what is really frustrating.
    (not so ergonomic, I know...)
    I hope it will help you to understand my trouble.
    regards

  • Pass parameters to a function in main class from loaded SWF?

    I've got a main.as that loads SWF to the stage.
    the loaded SWF seppoused to pass a link to the main.as and trigger a javascript function to popUp that photo from that link.
    I know there are two ways:
    ((root as MovieClip).parent.parent as Object).somefunction(parameters);
    and to dispatch an event.
    inorder to pass parameters throug the event i need to extend it with another class.
    isnt the (root as... )  more efficient if all i need is to pass a link?

    when a photo from the gallery is selected a javascript popUp shows it enlarged with additioan editing options (kinda like in facebook).
    in that popUp ther is also a next button so its kinda bidirectional. (the next calling the loaded SWF throug main to get the next link in the photo array)
    the photo is a grandchild of a grandchild of the stage and the loaded swf is a grandchild so using:
    ((root as MovieClip).root as MovieClip).ExternalInterface.call("ShowPic", link);
    is discusting ><

  • Calling Flex function from loaded SWF

    Hello,
    I need to load an external SWF file, wity ability to call functions from the base FLEX code script .
    Is that possible ? noting that the loaded SWF can be either in AS2 or AS3
    Thanks in advance ..

    There are some third party ways of talking to an as2 swf.  Google
    as2interface (or maybe as3interface)

  • Invoking class from loaded swf

    I'm working on a project where I'm loading in a video player
    as an external swf to my main movie. I'm not able to get my video
    or the custom player to show up, but sound is there (I've done the
    whole Library>New Video thing, so I have a video object to
    reference).
    My question is: My loaded swf uses #include to include a
    script which imports two classes from a subdirectory, could that be
    causing the problem? My main movie never uses the classes.
    Just want to make sure this isn't my problem before I go
    digging into the script again!

    That is unlikely to be the problem. The .as includes are
    compiled into the
    SWF at publish. Much more likely is that you have
    inappropriate references
    to _root in your loaded movie. As it stands, the scope of
    _root, once you
    load the movie into another, is the _root of the *loading*
    movie. Either
    change these refs, or set the _lockroot property of the mc
    you are loading
    into to true.,
    Remove '_spamkiller_' to mail

  • Accessing OID API from Javascript

    Hi,
    is there a way to access OID API directly from the client side ? using javascript ? Thanks.
    To help you understanding what I intend to do : I need to display a hyperlink but this hyperlink will be dynamic based on the "location" of the current user. This "location" can be found by querying OID.
    Thanks.
    Jeff

    Hi
    You don't need client side scripting, neither XMLHTTPRequest. Just write a small PL/SQL procedure on the serveur that will create the link you want based on the current user/location retrieved from OID, then call it for instance with a dynamic page
    In a dynamic page, write
    begin
    portal.my_package..my_proc;
    end;
    and my_proc on the server would do something like :
    declare
    lc_url long;
    begin
    -- retrieve into lc_url the oid info you need for current user, may be using additionnal wwctx_api library
    htp.p('<a href="http://my_serveur/' || lc_url || ">link</a>');
    end;
    Loko

  • Accessing movie clip from flash swf file

    I have the situation where in flash i created a simple
    animated movie clip with few stop() commands on timeline. Movie
    clip consists of simple animatio played on roll over and on roll
    out which is controlled using actionscript. I loaded movie clip
    into flash using [embed] tag but actionscript code is stripped,
    there is no stop() action so movie clip loops continously. I guess
    that's normal behaviour for embedded flash swf files but i would
    like to know is there a way to still achieve that? Can i load swf
    some other way with its actionscript and then control movie clip
    from flex?

    You need the FLA's to open in Flash.
    You could download the free trial of a flash decompiler
    (www.sothink.com). The free trial won't give you actionscript, but
    it will give you all of the art in the swf.

  • Control main timeline from loaded swf.

    Hi,
    I'm using a textfield for debug information.
    I'm loading an swf on the main timeline and I'm showing the status in the debug textfield.
    function swfLoaderCompleteHandler(event:Event)
         Debug.text +=  "Swf loaded.";
    That works.
    But,
    I'm loading a png file in the loaded swf. , I'm trying to show the status of the png file as I showed the status of the swf.
    function pngLoaderCompleteHandler(event:Event)
         MovieClip(parent).Debug.text += "Png loaded.";
    I can't control the main swf from inside the loaded swf. Even gotoAndStop or calling a function doesn't work.
    Do I need to add something when I load the swf, saying it's a MovieClip or something?
    Here's a fla too. http://flashfocus.nl/forum/attachment.php?attachmentid=9885&d=1282509233

    Thank you! you're brilliant!
    For people with the same problem:
    If you use CS5 and you have a TLF text on the stage, it doesnt work... I think it's a bug. But when I converted my TLF textfield to classic and everything works fine!

  • Accessing UWL API from Web Dynpro Java

    Hi experts,
    I need to retrieve the data from UWL into Web Dynpro java, I have gone through many blogs and solutions but since I am new to portal I am unable to a get hang of it. Can anyone provide me step by step solution including codes for my problem?
    Thanks & Regards,
    Amit Sinha.
    P.S. Points will rewarded.

    Hi Amit,
    just gothrough this below link... here they given the coding also.....
    Accessing UWL-API out of Web Dynpro Java
    it may be helpful to you.... pls comeback if you are struck any where......
    Regards,
    Srinivas.

  • Getting properties from loaded swf

    hi there,
    I am loading different swfs into my loader object "loader"
    and I also have a description of each swf below it ("desc"
    "desc_back").. Each swf is different in size and i want to move/
    scale "desc" and "desc_back" it to fit. This seems to be kind of
    working but it changes to fit the loaded swf before the one I want
    it to. it is if it is taking the properties of the last loaded swf
    instead of the one just loaded...I have tryed using an onload
    listener amoung a number of things. my action script is not very
    strong so it could be something simple.
    thanks :)

    you must wait until loading is complete before trying to
    access the _width and _height of the about-to-be-loaded swf. ie,
    use preloader code or the onLoadInit() method of the
    moviecliploader class.

  • Adobe AIR memory leak loading SWFs

    I was plagued by a memory leak that would crash my application after a few hours. The application had worked fine in the past but now was having issues and I thought it might have to do with using newer SDK's.
    In the end I discovered that if I loaded external swf that had been compiled in debug mode, they would not clear completely on unload and cause a memory leak.
    Compiling in release mode fixed the issue. Spent 3 days trying to figure it out.

    Any chance you can check that out with the latest AIR?
    Either way, it sounds like a bug, please report it at http://bugbase.adobe.com/ and then report the bug number here. 
    If you're able to provide a reproducable case that would really increase the chance that we can do something about it.
    Thanks,
    roymeo

  • Extract graphics from loaded swf / Big problem

    Hello,
    my English isn't very good, so sorry for mistakes I have swf which consist of many vector graphics.
    You can show it right here: http://www.watchtime24.sisco.pl/moje...orowanka_1.swf
    If I import the swf to the stage, than I can manipulate this graphics. But this is not enough for me. I need to manipulate from Action Script.
    I need to change the colors of this piceses from AS. I tried to use function
    getObjectsUnderPoint(new Point(mouseX, mouseY))
    but it doesn't work. This function doesn't see shapes, graphics or something else.
    Is any solution which can fix my problem ? Has anyone any idea ?

    Hey Mich,
    What you can do is turn eachof the items in your shapes, into a movieClip or sprite or even a bitmap.
    like the boy in the drawing.. take all of thsoe and then convert them into a movieClip.  Then when you do this give them a name and export them for actionscript.  Give this a class Name.
    then when you load the swf, you can actually target those files with this line.
    Say i converted the BOY into a movieClip.
    import flash.system.ApplicationDomain
    import flash.utils.geClasstDefinition
    var myswfHoldingBoy
    var myLoader:URLLoader = new URLLoader()
          myLoader.addEventListener(Event.INIT,onInit)
         var myURLRequest('path to myswfHoldingBoy')
    myLoader.load(myURLRequest)
    privaate function onInit(e:Event){
    //here is where we will extract the boy for the library of the other swf
    var ldrAppdomain= e.target.loaderInfo.applicationDomain
    var boyObject:Class= ldrAppdomain.getByDefinition('class name you gave the boy as i said eralier') as Class
    // now we have boyObject that will be able to be used as a class
    addChild(new boyObject())  // this will addYourBoy movieClip to the stage.  but keep a reference to him so that you can then manipulate him.

  • Creating array of Bitmaps from loaded swf

    so ive got a swf, quite simply it contains an embedded Video
    object, an flv. what i need to do is load it in (done) goto each of
    its frames in turn and convert said frames to Bitmaps, thus
    creating a single, unique Bitmap for each frame of the flv Video.
    crikey, how the hell can i do this? :)

    so i've just discovered that, as someone on some webpage
    somewhere said 'BitmapData is your friend. having discovered this i
    found the answer. the code's a bit rood, just test code crudely
    c&p'ed but heres what seems to be the broad answer to my own
    question:
    private function completeHandler(event:Event):void
    var mc:MovieClip = MovieClip(loader.content);
    mc.gotoAndStop(1);
    var bmd1:BitmapData = new BitmapData(320,240);
    var bm1:Bitmap = new Bitmap(bmd1, "auto", true);
    bmd1.draw(mc);
    mc.gotoAndStop(1000);
    var bmd2:BitmapData = new BitmapData(320,240);
    var bm2:Bitmap = new Bitmap(bmd2, "auto", true);
    bmd2.draw(mc);
    addChild(bm1);
    addChild(bm2);
    bm2.y = 240;
    }

  • Can't Access MovieClips and Functions in Loaded SWF

    Hi everybody,
    I'm trying to simply access anything inside this loaded SWF and all I get is 'null'.
    I have code in the parent SWF that needs to tell the child SWF movieclip what to do but nothing works. This was a piee of cake in AS2 and I can't seem to get anything to crossover in AS3.
    Here's my code:
    import com.greensock.TweenMax;
    import flash.display.MovieClip;
    var myLoader:Loader = new Loader();
    var url:URLRequest = new URLRequest("SWCS_S3_500x250_exp_panel_2.swf"); // in this case both SWFs are in the same folder
    myLoader.load(url);  // load the SWF file
    panel2.addChild(myLoader);   // add that instance to the display list, adding it to the Stage at 0,0
    panel2 = myLoader.content as MovieClip;
    photo_about.alpha = 0;
    photo_downloads.alpha = 0;
    //panel2.content_about.alpha = 0;
    //panel2.content_downloads.alpha = 0;
    function closeSection():void
              panel2.controlsMC.forcePause();
              TweenMax.to(photo_about, .5, {alpha:0});
              TweenMax.to(photo_downloads, .5, {alpha:0});
              TweenMax.to(photo_home, .5, {alpha:0});
              TweenMax.to(panel2.content_about, .5, {alpha:0});
              TweenMax.to(panel2.content_downloads, .5, {alpha:0});
              TweenMax.to(panel2.controlsMC, .5, {autoAlpha:0});
              TweenMax.to(panel2.content_home, .5, {alpha:0});
    panel2 traces null and all the clips loaded within pull up undefined property errors.
    Can somebody please tell me what I'm doing wrong? I'd be stoked to know what I'm missing and feel like this should be a piece of cake.
    Thanks for any help!

    You are not adding the content to the stage at 0,0, you are adding it to panel2 at 0,0.  THen you take panel2 and assign it to be something that likely doesn't exist by the time you assign it.  You need to wait until the loader completes loading before you attempt to do anything with its content, otherwise it has no content (null).  Similarly, you cannot control anything in the loaded swf until it has finished loading.  So assign an event listener to the contentLoaderInfo property of the Loader to determine when loading is complete, and have the event handler function deal with starting the interaction with it.
    var myLoader:Loader = new Loader();
    var url:URLRequest = new URLRequest("SWCS_S3_500x250_exp_panel_2.swf");
    myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, processLoadedSWF);
    myLoader.load(url);
    function processLoadedSWF(evt:Event):void {
        // deal with the loaded swf here
        // but you don't want to be assigning it to the panel2 object that contains the loader
    As far as controlling anything inside the swf you load, is it an AS1/2 or an AS3 swf?

Maybe you are looking for

  • How can I delete or add a file in thunderbird?

    The files on the left side of the window - somehow a file got underneath the trash file - I want to delete it and cannot seem to do it - I've tried right clicking - doesn't work. It must be simple - I just cannot do it

  • Ipad air 2 touch id not working when plugged in

    A very strange problem tonight. After work, I grabbed my iPad Air 2 which was plugged in to the Apple Charger next to my chair.  Touched the home button to open it - nothing happened.  Tried again.  Nothing happened.  Entered the code and the IPad Ai

  • Business Activity Monitoring of ODI integration process.

    Dear All, I would like to understand steps or methdology, to implement monitoring of Integration process in ODI 11g so that business users can monitor the success and failure of the scheduled process in production environment.. Thanks and Regards

  • General Account Determination

    1.Whre do we account purchase offset account. whether it is   a Expense A/c or Incomes Account 2.  What account we can assign for Sales Credit Account And Purchase Credit Account  . ? 3.  How we can differentiate Expense and Incomes of a busines for

  • Spotlight only displays PDFs - how to see all search types?

    Problem: When I enter search criteria into spotlight, the results only show one type of search.  For example, if PDFs are included in the preferences, I only see PDFs, not Documents and PDFs.  Turning off PDF in the spotlight preferences, results in