Listening to Events from inside loaded swf

In Flash Builder 4 I have a swfLoader with which I load swf files. The swf files that get loaded get created in Flash Pro, and I would like to be able to listen for events from the level that they get loaded from. What would I have to specify in the Flash file for the path? Can't seem to be able to specify the right path.
Thanks a lot for any help!

I wouldnt say this is elegant but we have been having issues gaining direct access to the SWF's loaded in via OSMF. However I have done setups where I dispatch an event from a SWF and have it bubble up and catch it on the MediaContainer level. Not elegant but works- otherwise may need to make a custom MediaElement and bypass the SWFElement to gain tighter control - seems like there should be a better way, but I havnt found it.

Similar Messages

  • Listen for events from an embedded Swf

    Hi there,
    I have spend so long searching for an answer on the web but can not find any that works, please help!
    I'm not even sure if this is possible but if anyone can guide me in the right direction I would most appreciate it!
    Basically what I would like to do is to load a swf in to my flex application - contrary to my post title it doesnt even have to be embedded - when the loaded swf finishes playing it's animation I want for it to dispatch an event and for flex to listen for that event and trigger a function when the event is captured.
    The animation is made in Flash CS3. I have not used any classes, rather on the last frame I set up an action to dispatch an event like this:
    dispatchEvent(new Event("finishedPlaying"));
    In my Flex Application I load my swf using swfLoader and I add an event listener to it like so:
    mySwfLoader.addEventListener("finishedPlaying", test);
    and my function is like this:
    private function test():void
         trace("it worked!");
    This is not working at all and I'm sure I am missing something but I cant seem to find any straightforward answer on the internet!
    Is it at all possible for a swf made in flash to communicate with flex??
    Since they are both written in AS3, I figured it would be easy but alas!
    If anyone can help me I would most appreciate it, thank you in advance!!
    By the way I have also tried:
    mySwfLoader.content.addEventListener("finishedPlaying", test);
    but no luck....

    You have to wait for the swf to complete loading before adding the event listener.
    When are you adding the event listener?
    mySwfLoader.addEventListener("finishedPlaying", test);
    Have a look at the SWFLoader complete event:
    http://livedocs.adobe.com/flex/3/langref/mx/controls/SWFLoader.html#event:complete

  • Passing events from externally-loaded SWFs

    Hi,
    We have an externally-loaded swf that acts as a kind-of-a slide show.  After a user selects a particular subject from a mxml-based "menu" application, they push "buttons" in the SWF to go through a presentation, then on the last frame of the swf, I'd like to unload the swf and replace it with another "mxml" application.  How can this be done?  I have not tried to pass/capture events "up" from an externally-loaded swf before.
    Thanks,
    Doug

    Do you own those SWFs?  If so, they should dispatch an event from a known
    place like a SlideShowManager or something like that.
    Other folks "cheat" and bubble events or dispatch off of the systemManager
    and/or top-level application.

  • Accessing events from externally loaded swf file

    hello,
    I have an swf file developed in flash 8. After loading that
    file into SWF Loader control in flex builder 3, how can we access
    the controls and events present in that particular file ?

    "surya_dhul" <[email protected]> wrote in
    message
    news:gg84e2$slm$[email protected]..
    > hello,
    > I have an swf file developed in flash 8. After loading
    > that
    > file into SWF Loader control in flex builder 3, how can
    we access the
    > controls
    > and events present in that particular file ?
    I think you'll need to use localConnection.

  • Controlling a Movie Clip on the Main Timeline from a loaded SWF?

    Is it possible to control a MovieClip on the main timelne from another loaded clip?
    I see posts that control loaded clips, but most are all from the loader in the main timeline.  I have a moviclip on the main timeline that I want to make visible or invisible depending on what keyframe is playing in another loaded swf.
    If I try to call the movieClip from the loaded SWF I get "error #1119.  Access of possibly undefined property...." because it doesn't exist in the loaded SWF, just the main timeline. 
    The old AS2 way just used "_root".  Since "_root" doesn't exist any more, how do you control items on the main TimeLine from a loaded SWF?

    I am not clear what you mean because you are saying you are trying to target a movieclip that does not exist where you are trying to target it.
    Try using a trace to see what you are targeting when you you target the MovieClip(parent.parent)....
    trace(MovieClip(parent.parent));
    The other approach I mentioned earlier is the more OOP-correct approach if you would rather try that way.  Here's a rough outline of it...
    AS3 - Dispatch Event
    http://forums.adobe.com/thread/470135?tstart=120
    Example:
    Add something to trigger the event in the child (your loaded swf):
    dispatchEvent(new Event("eventTriggered")); (
    if dispatchEvent problem, see: http://www.kirupa.com/forum/showthread.php?p=1899603#post1899603)
    In your loading/parent swf, listen for the complete event on the Loader.contentLoaderInfo.  In the complete event handler, add a listener for the event on the loaded swf.
    // event handler triggered when external swf is loaded
    function loaderCompleteHandler(event:Event) {
        MovieClip(event.currentTarget.content).addEventListener("eventTriggered", eventHandler);
    function eventHandler(event:Event):void {
        trace("event dispatched in loaded swf");
       // this is where your main file can set the visible property of your movieclip

  • Calling a function in the main movie from a loaded swf

    I realize this is probably a very basic question, but I have
    loaded a SWF file into another movie. I now want to call a function
    in the main SWF. Is there a way to do that? Alternatively, I have a
    custom class where I could put the function, but I haven't been
    able to figure out how to call it from the loaded SWF either. Do I
    somehow need to associate the class with the main movie,
    or...?

    Never mind - I was doing something very stupid and wasn't
    calling the function as a method of a movie clip. I was simply
    calling checkTarget(event) rather than
    event.currentTarget.checkTarget(event); which seems to work.

  • Calling a function in a flex app from a loaded SWF

    How can I call a function in a flex application from a loaded
    swf file?

    Two ways:
    Application.application returns a reference to the top-level
    application scope. You can access any public member, var, function,
    component, etc through that reference.
    Dispatch an event event form the loaded swf and use a event
    handler in the main app. All the gurus advise this as best
    practice, to ensure "loose coupling" It is also pretty easy,
    especially if you use a bubbling event.
    Tracy

  • Listen for Events from anywhere

    Hello!
    I have an application with a rather complicated component hierarchy.
    How can I have it so that I can listen for events from any component in any component, regardless of who is who's child?
    Thank you!

    You need a broadcasting mechanism.
    Many architecture framework offers this facility, but as a quick hack you can try something like
    public class Broadcaster extends EventDispatcher  ( singleton anti pattern   )
    instance
    then just do Broadcaster.instance.addEventListener or removeEventListener. it's a crappy singleton, but at least it does not hold any global state.
    I've also seen people use Application.application to dispatch/listen globally but really don't like it.
    Note : Use weak references or your views will never be eligible for garbage collections.

  • Listening for UncaughtErrorEvents from SubApp loaded by SWFLoader

    I can't seem to get my uncaughtErrorEvents listener to fire when attached to the loader.uncaughtErrorEvents  or loaded content's loaderInfo.uncaughtErrorEvents when loading a swf via SWFLoader.
    I have a main Flex Application ('A.swf') loading a SubApplication  (defined in' B.swf') via a SWFLoader and I need to listen for  UncaughtErrorEvent from the SubApplication. I'm not able to get my event  listeners to be called when I throw an error from within the SubApp  ('B.swf').
    After reading the asDoc for UncaughtErrorEvent and  UncaughtErrorEvents It states that the UncaughtErrorEvent should go through the normal capture, target, and bubble phases through the loaderInfo hierarchy. This doesn't seem to be the case or I'm not understanding the documentation/usage.
    I have added an event listener to A.swf's loaderInfo  (The 'outter' main app) and also to B.swf's loaderInfo (though the Docs  say not to do it here it is part of the event sequence in the capture  and bubble phase...) as well as the SWFLoader internal  FlexLoader.uncaughtErrorEvent (per Docs) like so:
    SWFLoader's internal FlexLoader uncaughtErrorEvents
    swfLoader.content.loaderInfo.loader.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorFunction );
    and the loaded SWF's loaderInfo:
    swfLoader.content.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorFunction );
    When I throw an Error from the SubApplication (B.swf). Only the 'outter' main app's (A.swf) event listener gets called. Which you expect, at first, if it is in the capture phase, but it isn't in that eventPhase at all. When debugging the eventPhase is in the EventPhase.AT_TARGET phase while being handled by A.swf's LoaderInfo, howeever the ASDoc says the Target phase should be B.swf's LoaderInfo.
    Is this a bug between Flash player and Flex where the event isn't flowing correctly as stated in the ASDoc for UncaughtErrorEvent?

    Thanks for the reply Alex.
    The Outer main swf and the SubApp swf are in different ApplicationDomains (sibilings to each other) so they should not be sharing the class that is throwing the error. I should note that these two Applications are purely based on MX components, this is important later on.
    I was originally throwing the error from a Button click handler from B.swf:
    <mx:Button label="Throw Error" click="callLater( throwUncaughtError )" />
    I was wrapping the handler function in a callLater because without it the error is not caught at all and the default flash dialog console just appears with the error. The A.swf's loaderInfo.uncaughtErrorEvents handler was not even firing unless I wrapped it a callLater.
    I realized that Flash Builder's default to link the 4.1 SDK library via Runtime shared libraries was what was causing the A.swf's loaderInfo.uncaughtErrorEvent to fire in the AT_TARGET phase when using callLater. This is because the UIComponent's callLater method queue structure is shared between the two SWFs and therefore inside a function executing off the method queue A.swf's loaderInfo IS the TARGET... explainable, but at first thought that isn't how I'd expect this to work.
    I then decided to test this out by setting the SDK library to merge into the code for both A.swf and B.swf and removing the  callLater. IT WORKS!  B.swf's (the SubApp) loaderInfo.uncaughtErrorEvents handler fires and I prevent the default (flash error console from appearing) and can stopImmediatePropagation so A.swf's loaderInfo.uncaughtErrorEvents handler doesn't fire.
    Perfect besides having to merge the SDK libraries into each swf independently.... size killer.
    In summary, using the same exact code for A.swf and B.swf:
    1. When the SDK libraries are RSL - no UncaughtErrorEvents, neither A.swf's or B.swf's, is called. Instead the default flash error console appears with no chance to handle the uncaught error.
    2. When the SDK libraries are Merged into the code - both A.swf's and B.swf's uncaughtErrorEvents  will be called, according to the asDoc documented sequence; B.swf's uncaughtErrorEvents in the AT_TARGET phase and A.swf's uncaughtErrorEvents in the BUBBLE phase.
    Moreover, if I build a pure Spark implementation everything works even when referencing the SDK libraries as RSL.
    Does this indicate a bug in the globalplayer (flash player code)'s logic for handling UncaughtErrorEvents listeners within the loaderInfo hierarchy when the Flex SDK is Shared code between the SWFs?
    OR
    Since it works in Spark, is it an issue with how the flex2.compiler.mxml.Compiler turns MX based mxml components into generated AS classes (it hooks up the inline event listeners of child UIComponentDescriptor using a generic object and the click function is specified as a STRING and has to use untyped bracket notation to lookup on the UICompoent when adding it as a listener:
    new mx.core.UIComponentDescriptor({
                  type: mx.controls.Button
                  events: {
                    click: "___B_Button1_click"
                  propertiesFactory: function():Object { return {
                    label: "Throw Error"
    Where as Spark does this correctly and generates Factory functions for setting up child UIComponents when converting Spark component mxml to AS:
    private function _B_Button1_c() : spark.components.Button
        var temp : spark.components.Button = new spark.components.Button();
        temp.label = "Throw Error";
       temp.addEventListener("click", ___B_Button1_click);
        if (!temp.document) temp.document = this;
        mx.binding.BindingManager.executeBindings(this, "temp", temp);
        return temp;
    * @private
    public function ___B_Button1_click(event:flash.events.MouseEvent):void
        throwUncaughtError()
    Sadly, moving to pure Spark would be a big hit is my project's schedule and at this point and likely isn't feasible. I have examples (with view source) built in MX for both the RSL and MERGE cases, I just don't know how to attach them here.
    Sorry for the long comments and thanks again!

  • Turning the page in a pdf from inside a swf video

    I am creating interactive PDFs from InDesign. On the first page of the pdf I have a swf video in which I would like to put a link or a button that would move you to page 2 of the pdf. Not another frame of the video or URL, but just the next page of the PDF. Is it possible to do this? And if so, how?

    You don't make it clear what you're using. A "SWF" is a Flash file, and a video is a video. A SWF can load and play a video, but "SWF video" means nothing.
    If you're talking about a SWF file created in Flash, then inside your SWF you will have to fire an ExternalInterface command using ActionScript:
    ExternalInterface.call(“eval”, “pageNum++”);
    If you're talking about a video file embedded in the PDF and using the default playback widget, then you can't do it.

  • Can't target main stage from dynamically loaded swf...

    A part of the Flash app. I'm working on right now does the following -
    Main stage loads an external swf using the following function:
    function loadAsset(evt:String):void{
    var assetName:String = evt;
    if (assetName != null){
      var assetLdr:Loader = new Loader(); 
      var assetURL:String = assetName; 
      var assetURLReq:URLRequest = new URLRequest(assetURL); 
      assetLdr.load(assetURLReq); 
      assetLdr.contentLoaderInfo.addEventListener( Event.INIT , loaded) 
      assetLdr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, displayAssetLoaderProgress);  
      function loaded(event:Event):void { 
       var targetLoader:Loader = Loader(event.target.loader); 
       assetWindow.addChild(targetLoader);
    The externally loaded swf loads another external swf into itself using the following function:
    function loadQuiz(evt:String):void{   
    var quizName:String = evt;
    if (quizName != null){
      var quizLdr:Loader = new Loader();
      var quizURL:String = quizName;
      var quizURLReq:URLRequest = new URLRequest(quizURL);
      quizLdr.load(quizURLReq);
      quizLdr.contentLoaderInfo.addEventListener( Event.INIT , loaded)       
      quizLdr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, displayQuizLoaderProgress); 
      function loaded(event:Event):void {
       var targetLoader:Loader = Loader(event.target.loader);
       quizWindow.assetLoader.addChild(targetLoader);     
    Everything loads fine, but from the quizWindow.assetLoader.addChild(targetLoader) level, I want to send a message/fill in a dynamic text box on the Main Stage. I have been "parenting" my brains out and I'm not sure how to communicate with that level.
    can anyone show me the proper path or method based off the above, or have a suggestion?
    Cheers,
    ~Chipleh

    Andrei1,
    Thanks again for your help. I was finally able to get the solution you posted below to work for me.
    Much appreciation,
    ~Chipleh
    "In your loaded movie write:
    function traceMyself(e:MouseEvent):void{
         dispatchEvent(new Event("I_WANT_TEXT"));
    function writeText(text:String):void {
         xmlFileName1.text = text;
    In the top movie that loads external swfs something like that:
    loadedSwf.addEventListener("I_WANT_TEXT", onTextRequest, true);
    function onTextRequest(e:Event):void {
         Object(e.target).writeText(tQuizXmlFile1.theQuizXmlFile.text);
    This way these two entities are independent and, most importantly, don't care who is the parent or grandparent."

  • Moving the timeline from a loaded swf file

    Hi,
    I have been at this problem for awhile now.
    I have a two swf files, whic are loaded using ths code as an example:
    stop();
    var req:URLRequest = new URLRequest("Enchilada_A.swf");
    var loader:Loader = new Loader();
    function imageLoaded(event:Event):void {
        ldContainerB.addChild(loader);
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
    loader.load(req);
    The first one is triggerrd by a MC button that is on the timeline.
    That first swf loads fine.
    At the end of that file(which is short animation)
    I have code that says:
    MovieClip(parent).gotoAndStop("frameThree");
    I have also tried:
    MovieClip(root) and
    if (movie Clip is parent) {
    MovieClip(parent).gotoAndStop("frameThree");
    and/MovieClip(parent).nextFrame();
    I have also tried placing this. or root. into the code.
    I am not talking to the timeline from this swf file.
    Once the timeline moves to the next Frame the new swf file can load.
    My solution was to combine both swf files into one, which loads from the timeline button.
    It works and I can gt by but I really woud like to learn how to load a swf and talk to the timeline fro more flexibilty.
    I'm out of strategies.
    Is my code in the wrong place(at the last frame of the animation?
    Should it be written on the timeline by creating a new var that has a function once the animation is completed.
    Any suggestions and/or commens would be greatly appreciated.
    Thanks.

    Thanks,
    I finally had a chance to get back to this project and used your suggestions, whichare definitiley helpful. I also, created a new and very basic version of the project so I could easily see what was happening.
    This is the code that works:
    stop();
    MovieClip(parent.parent).nextFrame();
    trace(container_mc);
    I'm still trying to understand how the child parent relationship is working but this will get me going in the right direction.

  • Scrollpane all screwy  inside loaded swf

    I have had this problem using both the scrollPane component
    from Flash 8 and an open source code scrollpane that I found in
    Flashkit. I have an swf in which I'm using a scrollPane which works
    fine when I test the movie. However, I'm loading this swf into
    another master swf using loadMovie. When I do this, the scrollpane
    inside the loaded swf gets really buggy. First, the scrollbar will
    not stop scrolling when I release the mouse. Also, the whole
    scrollPane gets a green highlight around the edges (except in the
    open-source code scrollpane). HELP!! Does anyone know how to load a
    scrollPane into another swf without it getting all weird?

    //below is the code for the "slideshow.swf"
    //For the main movie.. I'm doing....
    button_btn.onRelease = function() {
    myMovieClipLoader_mc.loadMovie("slideshow.swf")//
    this.createEmptyMovieClip("container_mc",this.getNextHighestDepth());
    this.createEmptyMovieClip("buttons_mc",this.getNextHighestDepth());
    //loader//
    this.attachMovie("loader2","loader_mc",this.getNextHighestDepth());
    loader_mc._x = (Stage.width - loader_mc.width)/2;
    loader_mc._y = (Stage.height - loader_mc.height)/2;
    var myMCL:MovieClipLoader = new MovieClipLoader();
    var myListener:Object = new Object();
    myMCL.addListener(myListener);
    myListener.onLoadProgress =
    function(target,bytesLoaded,bytesTotal) {
    loader_mc._alpha = 100;
    var pct = Math.round(bytesLoaded/bytesTotal*100);
    loader_mc.bar_mc._xscale = pct
    myListener.onLoadComplete = function(target) {
    loader_mc._alpha = 0;
    //button movies//
    buttons_mc.attachMovie("prev","prev_mc",buttons_mc.getNextHighestDepth());
    buttons_mc.attachMovie("next","next_mc",buttons_mc.getNextHighestDepth());
    buttons_mc.next_mc._x = Stage.width -
    buttons_mc.next_mc._width;
    buttons_mc.next_mc._y = 10;
    buttons_mc.prev_mc._x = 10;
    buttons_mc.prev_mc._y = 10;
    //variables//
    var numPics:Number = 5
    var picArray:Array = new Array();
    var currentElement:Number = 0;
    for (i=0;i< numPics;i++) {
    var location:String = "pics/pic0" + (i+1) + ".jpg";
    picArray.push(location);
    myMCL.loadClip(picArray[currentElement],container_mc);
    //next button//
    buttons_mc.next_mc.onRelease = function() {
    if (currentElement < picArray.length-1) {
    currentElement++;
    else
    currentElement = 0;
    myMCL.loadClip(picArray[currentElement],container_mc);
    //prev button//
    buttons_mc.prev_mc.onRelease = function() {
    if (currentElement > 0) {
    currentElement--;
    else
    currentElement = picArray.length-1;
    myMCL.loadClip(picArray[currentElement],container_mc);
    }

  • Listening to event from custom component

    I have a main.mxml file, and 2 custom components: component1.mxml and component2.mxml
    I want to dispatch an event from component1 and handle it in component 2.
    I'm able to do this by handling the event first in the main.mxml then passing it on.
    But is there a way not to involve main.mxml, and to directly listen to the event from component 1 and handle it in component 2?
    I need to listen the event in actionscript, not mxml.

    You can dig in to custom event handlers
    Best Regards,
    Yogesh

  • AttachMovie from a loaded SWF

    I'm trying to attach a movie from the library of an SWF I
    loaded... from what I've read on on the forums, this is possible,
    however I can't seem to get it to work. My setup for the test files
    is as follows:
    CONTAINER.SWF (parent file)
    - creates empty_mc to hold child.swf
    - loads child swf into empty_mc
    - when child.swf is loaded, it calls:
    _root.attachMovie("test_mc","myParentTest_mc",50);
    CHILD.SWF (child clip)
    (insde is a clip "test_mc" with a linkID to match)
    Any help on syntax or what I might be doing wrong would be
    appreciated. If this setup won't work, could it work the other way?
    (CHILD.SWF attaches a symbol from the CONTAINER.SWF???)

    Thank-you for the response, I thought of that... In my
    situation, I need to be able to select one of many large files, and
    attach assets from it as needed. In order for me to use attach
    movie, using shared library assets, they first need to be placed on
    the stage before the linkID is properly initialized. If I have to
    do this for each "large file" it causes a jump in memory on file
    startup. See my other post in the Flash General Discussion:
    External
    Assets and Memory Jump

Maybe you are looking for

  • Replacing New Macbook Pro Hard Drive

    Im about to purchase a Seagate Momentus 7200.3 for my new MBP. My question is, will apple to the drive swap for me for free? Also will they migrate my old disk image to the the new drive, or will I have to reinstall OSX and migrate my files from a Ti

  • IPad Mini video to analogue problem

    I connect my iPad Mini to my Edirol V4 video mixer via the lightning VGA adapter and a scan converter to make the video signal analogue, but the resulting image is too narrow, like the pixel aspect ratio is wrong. A square will look like a tall recta

  • Exporting to flash/swf, losing drop shadow?

    Hi guys, when I add drop shadow to 2d text in AE it looks fine in the RAM preview, but when I export to a SWF object its gone.  I tried both the effect and layer style versions of drop shadow.. not really sure what the difference is anyways.  Any ide

  • Keyboard error in Dreamweaver CS3

    Dreamweaver part of the CS3 suite was working perfectly. Then... recently certain keys on my keyboard won't type at all. This is only in Dreamweaver. Puzzled as never encounterd this before (changed keyboard etc but same result) I dont usually work i

  • Can't use youtube controls / windows controls (Close, Minimize,etc)

    I cant use youtube controls, example play, volume, seek, etc (also with some other flash objects, not all) I Can't use the windows buttons on the top right hand side, example close, maximize, minimize,etc sometime I can't use non flash sections in so