i have a flash file, containing 2 scene.
first scene have continuous looping of random selected external flv file, using flvplayback.
second scene contain code for 2 external swf file, play after another. continuously.
however, it seem dont work for the second scene. it just wont get into the function.
here, i also paste down actionscript code for scene 2.
stop();
var myLoader:Loader = new Loader();
var url:URLRequest = new URLRequest("loader.swf");
myLoader.load(url);
addChild(myLoader);
stage.loaderInfo.addEventListener(Event.COMPLETE,playnextswf);
function playnextswf(event:Event):void{
trace("in function");
removeChild(myLoader);
var myLoader2:Loader = new Loader();
var url2:URLRequest = new URLRequest("intro.swf");
myLoader.load(url2);
addChild(myLoader2);
}
EDIT
i do some editing, by change this line of code:
.addEventListener(Event.COMPLETE,playnextswf);
to
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,playnextswf);
it seem to jump into function, but with error.
in function
in function
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at praperkahwinan_fla::MainTimeline/playnextswf()
I think you are looking more for:
var myLoader:Loader = new Loader();
var url:URLRequest = new URLRequest("loader.swf");
myLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, playnextswf );
myLoader.load(url);
addChild(myLoader);
You attached the listener to the stage loaderInfo which works a little differently, from adobe:
The LoaderInfo class provides information about a loaded SWF file or a
loaded image file (JPEG, GIF, or PNG). LoaderInfo objects are
available for any display object. The information provided includes
load progress, the URLs of the loader and loaded content, the number
of bytes total for the media, and the nominal height and width of the
media.
As we discussed in chat you are looking for something more like this:
var myLoader:Loader= new Loader();
myLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, onLoaderComplete );
myLoader.load( new URLRequest( "loader.swf" ) );
var myLoaderSwf:MovieClip;
function onLoaderComplete( e:Event ):void {
trace( "first swf loaded" );
myLoaderSwf = e.target.content as MovieClip;
addChild(myLoaderSwf);
myLoaderSwf.addFrameScript( insert frame number, loadNextSwf );
myLoaderSwf.gotoAndPlay(2);
}
function loadNextSwf():void {
trace( "removing currently loaded swf -- loading next swf" );
removeChild( myLoaderSwf );
myLoader = new Loader();
myLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, onIntroComplete );
myLoader.load( new URLRequest( "intro.swf" ) ); //change this to intro.swf
}
function onIntroComplete( e:Event ):void {
trace( "intro swf loaded" );
myLoaderSwf = e.target.content as MovieClip;
addChild(myLoaderSwf);
}
Related
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
var file:FileReference=new FileReference();
and then
trace (file.data);
works fine
after that I'm trying to embed received data into the scene but with no success
var ExtSWF:MovieClip;
ExtSWF = file.data.readObject() as MovieClip;
trace(ExtSWF);
returns null
but if I load it as remote file, with Loader - it works fine
var ldr:Loader = new Loader();
ldr.load(new URLRequest("ext.swf"));
......
ExtSWF = MovieClip(ldr.contentLoaderInfo.content);
Is it possible to just upload swf file and embed it into the scene, or Loader class is the only possibility to archieve this goal?
The Loader class is used to load SWF files or image (JPG, PNG, or GIF)
files.
But "load" really meaning "decode format" for display. So pass your file.data bytes through the Loader using Loader.loadbytes for decoding to a valid MovieClip object.
Try
//var ExtSWF : MovieClip = new MovieClip;
//ExtSWF = file.data.readObject() as MovieClip;
var ldr : Loader = new Loader(); //# declare outside of any functions (make as public var)
ldr.loadBytes(file.data); //#use Loader to auto-decode bytes of SWF
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, on_swfLoaded );
And also have a handler function for the decoding completion...
function on_swfLoaded (evt:Event) : void
{
var ExtSWF : MovieClip = new MovieClip;
ldr.contentLoaderInfo.removeEventListener(Event.COMPLETE, on_swfLoaded );
ExtSWF = ldr.content as MovieClip;
trace(ExtSWF);
ExtSWF.x =50; ExtSWF.y = 50; addChild(ExtSWF);
}
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...
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
I would be very thankful if you help me with this problem.
I´m trying to play in my application for ipad one MovieClip once. i tried to do stopping in this way, but the movie dont stop
var loader:Loader = new Loader();
var swfFile:URLRequest= new URLRequest("/test.swf");
loader.load(swfFile);
movieClip = new MovieClip();
movieClip.addChild(loader);
movieClip.addFrameScript(movieClip.totalFrames - 1, callbackFunc);
movieClip.play();
private function callbackFunc():void
{
movieClip.stop();
}
var loader:Loader = new Loader();
var swfFile:URLRequest= new URLRequest("/test.swf");
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onFileLoaded);
loader.load(swfFile);
//I assume you have declared 'movieClip'?
//if not do:
//var movieClip:MovieClip;
private function onFileLoaded(e:Event):void
{
movieClip = loader.content;
addChild(movieClip);
movieClip.play();
addEventListener(Event.ENTER_FRAME, onEnter, true, 0, false);
}
private function onEnter(e:Event):void
{
if (movieClip.currentFrame == movieClip.totalFrames)
{
movieClip.stop();
removeEventListener(Event.ENTER_FRAME, onEnter, true, 0, false);
//do other stuff
}
}
This should do what you need.
var loader:Loader = new Loader();
var swfFile:URLRequest= new URLRequest("/test.swf");
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
loader.load(swfFile);
private function callbackFunc():void
{
movieClip.stop();
}
function onCompleteHandler(loadEvent:Event)
{
movieClip = MovieClip(loadEvent.currentTarget.content);
addChild(movieClip);
movieClip.addFrameScript(movieClip.totalFrames - 1, callbackFunc);
movieClip.play();
}
Your code will not work because it's not the movieClip that is played, it's the external SWF that you load into it that will play it's keyframes. The created movieClip only has 1 keyframe, and on that 1 keyframe the external SWf is placed. You should add the stop() function into the external SWF. If you do this correct the external SWF plays once, and is then stopped.
You can also wrap the external SWF into a new MovieClip and put the code you already have onto it...
Or If you want full control, you can adapt the external SWF code so that this dispatches an event when the last frame is played. Provide a custom stop / replay function on the SWF which you can then call from the parent SWF.
Good luck!