Load external SWF loader content not accessible - actionscript-3

Actually i have a SWF that is loaded by another SWF.
This SWF that is loaded, itself load another SWF.
This may be weird, but it's in a context of an online game that let you develop SWF as plugins.
So, we have SWFA(the video game) ---> SWFB ----> SWFC
When i try to load the external SWFC, the COMPLETE event fire, but i am only able to add it to the stage by adding directly the Loader, because the loader doesn't have any content property.
public function load(){
loader = new Loader();
loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIoError);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.NETWORK_ERROR, onIoError);
loader.contentLoaderInfo.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);
applicationContext = new LoaderContext(true, ApplicationDomain.currentDomain);
loader.load(getRequest(),applicationContext);
}
private function getRequest():URLRequest {
Security.allowDomain("https://mock.com");
Security.loadPolicyFile("https://mock.com/crossdomain.xml");
var req:URLRequest = new URLRequest("https://mock.com/mock.swf");
req.method = URLRequestMethod.POST;
req.data = new URLVariables("name=kk");
var encoder:Base64Encoder = new Base64Encoder();
encoder.encode("user:pass");
var credsHeader:URLRequestHeader = new
URLRequestHeader("Authorization", "Basic " + encoder.toString());
req.requestHeaders.push(credsHeader);
return req;
}
Here is the onComplete function
public function onComplete (e:Event):void{;
this.addChild(e.target.content); // this is null
this.addChild(e.currentTarget.content); // null too
}
So, when i run my SWF from my local computer, everything goes well, e.target.content contain my external SWF.
But when i run the same within the SWF Loader inside the online game, i can't find any content property. Plus, childAllowParent property of LoaderInfo is always false.
Does someone have an idea of what's going on?
Thanks

Related

How to load image to swf which is loaded into other swf? (AIR, AS3)

I have an application in AIR, which is loading swf files and makes previews of them. When those swfs loads other content (eg. jpg) then i have an error, that url not found - i am convinced that is about jpg file. This problem shows only when i load swf by filereference using loadBytes(). When i load swf by Loader using load() - problem doesn`t exist. How can i fix this issue? Sorry for my english. I attach code fragment with loading swfs.
private static function loadFile(loadType:String, swfNum:Number = 0):void {
lc = new LoaderContext();
lc.allowCodeImport = true;
lc.allowLoadBytesCodeExecution = true;
currentSwfNum = swfNum;
var fRef:FileReference = DataBase.swfsList[currentSwfNum];
fRef.addEventListener(Event.COMPLETE, onFileReferenceLoad);
fRef.load();
}
private static function onFileReferenceLoad(e:Event):void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, ifComplete);
loader.loadBytes(e.target.data, lc);
}
private static function ifComplete(e:Event):void {
var mc:MovieClip = LoaderInfo(e.target).content as MovieClip;
mc.addEventListener("SHOOT", SwfSingleCapture.captureSingleShoot);
}
DataBase.swfList - it is an array of FileReference objects, which are selected by FileReferenceList and browse().

Actionscript 3 - List error when loading another a swf in my swf

I am working on a AS3/Flash game and we are running into an issue when we load our home page swf into our login swf after someone successfully logs in.
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChildAt()
at fl.controls::BaseButton/drawBackground()
at fl.controls::LabelButton/draw()
at fl.controls::Button/draw()
at fl.core::UIComponent/drawNow()
at fl.controls::List/drawList()
at fl.controls::List/draw()
at fl.core::UIComponent/callLaterDispatcher()
We are developing in Flash Builder, importing a .swc with the artwork and components into our project. We load our homepage swf and add it as a display object like this:
private function LoadComplete(e:Event):void
{
//trace("LoadComplete");
m_loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, LoadProgress);
m_homePage = e.target.content as DisplayObject;
}
Adding it:
addChild(m_homePage as DisplayObject);
Is there a better way to load a swf into another swf? Why would we be getting errors when loading the homepage swf through our login swf but not when we are debugging the home page separately?
Any advice would be very helpful.
If you want to execute external swf inside your own swf, you'll need to use SWFLoader
<mx:SWFLoader
id="sfwLoader"
width="100%"
height="100%"/>
And load code:
protected function loadSWF():void
{
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, onSWFLoaded);
loader.load(new URLRequest("app-storage:/myOther.swf")); // sample location
}
protected function onSWFLoaded(e:Event):void
{
var loader:URLLoader = URLLoader(e.target);
loader.removeEventListener(Event.COMPLETE, onSWFLoaded);
var context:LoaderContext = new LoaderContext();
context.allowLoadBytesCodeExecution = true;
context.applicationDomain = ApplicationDomain.currentDomain;
sfwLoader.loaderContext = context;
sfwLoader.addEventListener(Event.COMPLETE, loadComplete);
sfwLoader.load(loader.data);
}
protected function loadComplete(completeEvent:Event):void
{
var swfApplication:* = completeEvent.target.content;
}
This laods any swf, so it's potential security hole. Regards providing security you can examine: http://mabulous.com/air-applications-that-can-be-updated-without-requiring-admin-rights

How to load new swf on mouseclick event of movieclip in as3?

I want to create a flip effect button, on click event of which a external swf should be opened removing all the contents of current swf.
I have created both components, a button and also a movieclip.
Neither of its load ( new URLRequest()) code working.
Below is the complete code I am using. Where btn2 is class name of my movie clip
and 2.swf is external swf I want to load.
stop();
var bc2:btn2 = new btn2();
bc2.buttonMode = true;
bc1.addEventListener(MouseEvent.CLICK, mouseClick);
var loader = new Loader();
function mouseClick(event:MouseEvent): void {
loader.unload();
loader.load(new URLRequest("2.swf"));
addChild(loader);
}
First btn2 instance what you are instantiating needs to be added for it to be visible.
Secondly you are trying to load the swf even before its loaded.
I have modified the code
stop();
var bc2:btn2 = new btn2();
bc2.buttonMode = true;
this.addChild(bc2);
bc2.addEventListener(MouseEvent.CLICK, mouseClick);
var loader = new Loader();
function mouseClick(event:MouseEvent): void {
loader.unload();
loader.load(new URLRequest("2.swf"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler, false, 0, true);
}
function completeHandler(event:Event):void{
this.addChild(loader);
}
This should work...

url request not working properly - video does not stop as3

I created an information kiosk on flash but I got a problem that is really annoying on loading my contents externally. I have exported all of my swf files and created a unique swf to load everything on it with the main menu on top. The main problem is streaming a video from youtube. It loads perfectly but when i navigate to another page, the page changes but the video does not stop if it has been played once.(the sound keeps playing). Here is my code:
loader1.fla:
// Container
var pageLoader:Loader = new Loader();
// Url Requests
var loadRequest1:URLRequest = new URLRequest("basics1.swf");
var loadRequest2:URLRequest = new URLRequest("climatechange.swf");
// Initial Page Loaded
pageLoader.load(loadRequest1)
addChild(pageLoader)
// Button Functions
function goHome (e:MouseEvent):void{
pageLoader.load(loadRequest1)
addChild(pageLoader)
}
hpage.addEventListener(MouseEvent.CLICK, goHome);
//go to climate change page
function climatePage (e:MouseEvent):void{
pageLoader.load(loadRequest2);
addChild(pageLoader);
}
climatep.addEventListener(MouseEvent.CLICK, climatePage);
climatechange.fla:
Security.allowDomain("http://www.youtube.com")
// load video
var pageLoader:Loader = new Loader();
// Url Requests
var loadRequest1:URLRequest = new URLRequest("overviewvideo.swf");
// Intial Page Loaded
pageLoader.load(loadRequest1)
addChild(pageLoader)
overviewvideo.fla:
/*youtube video*/
var player:Object;
var loader:Loader = new Loader();
var context:LoaderContext = new LoaderContext();
context.checkPolicyFile = true;
context.securityDomain = SecurityDomain.currentDomain;
context.applicationDomain = ApplicationDomain.currentDomain;
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
Security.allowDomain("http://www.youtube.com")
loader.load(new URLRequest("http://www.youtube.com/v/6s8iiIFgPMU&list=PL9C6D9D2AF8999F85&index=12"));
function onLoaderInit(event:Event):void {
addChild(loader);
loader.x= 40;
loader.y=130;
loader.content.addEventListener("onReady", onPlayerReady);
loader.content.addEventListener("onError", onPlayerError);
loader.content.addEventListener("onStateChange", onPlayerStateChange);
loader.content.addEventListener("onPlaybackQualityChange", onVideoPlaybackQualityChange);
}
function onPlayerReady(event:Event):void {
// Event.data contains the event parameter, which is the Player API ID
trace("player ready:", Object(event).data);
// Once this event has been dispatched by the player, we can use
// cueVideoById, loadVideoById, cueVideoByUrl and loadVideoByUrl
// to load a particular YouTube video.
player = loader.content;
// Set appropriate player dimensions for your application
player.setSize(480, 260);
}
function onPlayerError(event:Event):void {
// Event.data contains the event parameter, which is the error code
trace("player error:", Object(event).data);
}
function onPlayerStateChange(event:Event):void {
// Event.data contains the event parameter, which is the new player state
trace("player state:", Object(event).data);
}
function onVideoPlaybackQualityChange(event:Event):void {
// Event.data contains the event parameter, which is the new video quality
trace("video quality:", Object(event).data);
}
Can anyone help? I'd be glad if someone can help me out. Thank you
Before you load a new swf into the loader, you need to first call:
pageLoader.unloadAndStop();
Attempts to unload child SWF file contents and stops the execution of commands from loaded SWF files. This method attempts to unload SWF files that were loaded using Loader.load() or Loader.loadBytes() by removing references to EventDispatcher, NetConnection, Timer, Sound, or Video objects of the child SWF file. As a result, the following occurs for the child SWF file and the child SWF file's display list:
Sounds are stopped.
Stage event listeners are removed.
Event listeners for enterFrame, frameConstructed, exitFrame, activate and deactivate are removed.
Timers are stopped.
Camera and Microphone instances are detached
Movie clips are stopped.
Docs at Adobe

Instantiate Document Class in as3

hi need to instantiate document class in as3. I have a main movie which will load load.swf. The document class of load.swf is LoadedMovie. i use this code :
public function Main()
{
var url:URLRequest = new URLRequest("load.swf");
loader=new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading);
loader.load(url);
}
function finishLoading(e:Event)
{
var sn:LoadedMovie=new LoadedMovie();
addChild(sn);
}
it's added the movieclip and but my framescripts were not working. i have stop at last frame.
Is it any other way to do this.
The Loader will contain an instance of your loaded swf's document class once it's loaded. Simply addChild the loader and you're in business.
var url:URLRequest = new URLRequest("load.swf");
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading);
loader.load(url);
addChild(loader);
Instanciating from a loaded swf is slightly more complicated, you have to deal with application domains and such.