Load Flex4 application in Flash as3 - actionscript-3

I have created a plugin-enabled flash which reads a configuration file and loads several other flash files. All the files have been created by Adobe Flash CS5 . Recently i had to create a flex application which i want to load on stage of the main flash.
this.addChild(this.movieLoader);
this.movieLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, LoadedM);
this.movieLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadError);
this.movieLoader.load(new URLRequest(fmovie));
The LoadedM(..) is triggered every time and the loaded flash is placed into stage and positioned in LoadedM(..) .
When i load a FlashCS5 created swf, the loader.content is of type [object MainTimeline] while when i load the Flex4 application the loader.content is of type [object _Main_mx_managers_SystemManager]
My problem is that the flex application is not visible on stage nor the initialized/created events of the flex app are triggered even thow debug shows full load of the file.
I have already tried this solution but didnt do any good. i've checked the Event.INIT event of the loaded instead of Event.INIT and it's being triggered. But the anthropod debugged doest not report the the initialization of the flex app take place.
What am i missing?
Thanks in advance

You can read more about the problem at http://old.troygilbert.com/2009/05/loading-flex-based-swfs-in-as3-only-swfs/
If the above does not work, make sure that you are publishing your swf for flashplayer 10.2+

Related

How to tell when ExternalInterface is available when hiding and showing a swf

I've got a swf with some js callbacks registered using ExternalInterface. I hide and show the swf repeatedly, and I've learned that ExternalInterface is not available when the swf is hidden. I also noticed that the swfs constructor is called every time it shows again, which I've used to make sure I don't try to call an ExternalInterface function before its available. This makes me wonder though if there is also some way to reliably tell from inside the swf when it is hidden? I know as3 classes don't have destructors, but is there anything similar that could be used to fire an ExternalInterface event right before the swf becomes unavailable again? REMOVED_FROM_STAGE doesn't seem to help out with detecting this as it doesn't fire at all.
I'm using several methods of hiding and showing btw. Sometimes using angular's ng-hide/ng-show and sometimes the swf is within a bootstrap modal window.
Also, I've noticed Flash Builder can somehow tell when the swf unloads. I can add a button that sets 'display: none' on the embedded <object> and I get the [Unload SWF] message in the console in Flash Builder. Is this just a feature of the debug player, or is there some secret event Flash Builder knows of that I have yet to find?
You can use this code to check if a SWF can call ExternalInterface:
if(ExternalInterface.available) {
ExternalInterface.call("console.log","hello browser");
}

Never Have Access to Embedded SWF Content Through Loader

I am working on embedding a SWF that is just a converted PDF created with InDesign. The SWF is 15 pages, 1 page per frame. It does include TLF text and there is no way around that unless the document is completely recreated in Flash. The problem is that when I load the SWF into my application, I never have access to the root MovieClip.
this.loader = new Loader();
this.loader.contentLoaderInfo.addEventListener( Event.INIT, this.loaderInitHandler );
this.loader.contentLoaderInfo.addEventListener( Event.COMPLETE, this.loaderInitHandler );
this.loader.load( new URLRequest( "assets/doc.swf" ) );
When I look at the loader after both the INIT and COMPLETE events as well as later on by stopping the app in debug mode, I do not see a MovieClip. Instead, the loader.content is of type doc_fla.MainTimeline__Preloader__ which contains two children, an empty Shape and another Loader. That loader, when checking INIT and COMPLETE events results in the exact same situation and it appears to be a never ending line of Loaders whose contents are "Preloaders".
Could anyone shed some light as to what is causing this or how I might fix it? I've poured a good 2 hours into solving this and I am no closer to a solution than when I started.
ActionScript Mobile project
Compiling using AIR 3.6
Testing in emulator as well as on iPad and on Nexus 7
I recompiled the SWF and embedded the TLF libraries (under ActionScript settings, just set the TLF swc which was already there to be embedded) in it and this seems to have fixed the issue. I swear I had tried that before to no success, but it worked this time.

eventListener flash

I am working with AS3.
I simply can't remember what eventListener to use if I want it to start my function up by it self (as in not a mouseevent.CLICK)
It is intended for a quick flash banner, that should just start up when ever a user enters the site where it is located.
You don't need to hook into an event for this.
When the site is loaded, the swf will load and play.
If the site is refreshed, then the swf will be reloaded (from cache) and be replayed
So any code that instanciates your app will be executed.
You can do loaderInfo.addEventListener(Event.COMPLETE, _YourFunctionToBeExecuted) if you want to do something when your swf file has been loaded completely
Or
You can do addEventListener(Event.ADDED_TO_STAGE, _YourFunctionToBeExecuted) if you want to run your code when the display object has been added to the stage

Load as3 into as2 work only on _root

i made a simple test example in as2. This contains two buttons with the following handlers.
_root:
on (release)
{
this.loadMovie("AS3.swf");
}
_root.test.testmc:
on (release)
{
test.testmc.loadMovie("AS3.swf");
}
The AS3.swf is a video player(using youtube as3 api). If i load it into _root it works, but if i want to load it into any other place it doesn't. I searched and found this from adobe:
"SWF files written in ActionScript 1.0 or 2.0 cannot load SWF files written in ActionScript 3.0. This means that SWF files authored in Flash 8 or Flex Builder 1.5 or earlier versions cannot load ActionScript 3.0 SWF files.
The only exception to this rule is that an ActionScript 2.0 SWF file can replace itself with an ActionScript 3.0 SWF file, as long as the ActionScript 2.0 SWF file hasn't previously loaded anything into any of its levels. An ActionScript 2.0 SWF file can do this through a call to loadMovieNum(), passing a value of 0 to the level parameter."
Is the "_root part" of my code working because of the above "exception rule"? I am new to flash(yeah you could ask why i started with as2, unfortunately not my choice...) and i wonder if my thinking is right. Also if there is any sort of workaround(other than rewrite everything in AS3), let me know(maybe use of localconnection?).
Try this:
on root of as2:
test.testmc.loadMovie("AS3.swf");
or in the mc u want the as3 player:
this.loadMovie("AS3.swf");
Your second code is calling test.testmc.test.testmc because it is already placed in the "testmc" so you dont need to reference it with the full path. It's recommended that you use relative paths for things like this.
So, inside the mc testmc you just need to do this.loadmovie instead of searching for test.testmc INSIDE testmc.
Hope that was what you're looking for.

Adding an as2 swf to the stage in an as3 swf

I have a menu control (as2), that is completely self-contained and doesn't rely on any interaction with the parent (as3). The menu control does load an external xml file that is in the same directory as the swf.
The menu control works fine when I run it on its own. But when I import it into the Library of my as3 fla, add it the stage and run it, it just sits and does nothing.
I can see the images that are part of the control, which leads me to believe it can't load the xml, but I'm not sure.
Does anyone have any ideas about:
Loading an as2 swf into and as3 swf where they don't need to interact
Loading an external file into an swf inside of another swf
Have you tried with flash.net.Loader or if you are going for a Flex app: SWFLoader?