0

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

Al K
  • 141
  • 2
  • 11
  • if you don't clean up the page and stop the video, you're just loading something on top of it. You need to remove the loader or the page – Gone3d Jan 04 '13 at 20:39

1 Answers1

0

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

Jason Reeves
  • 1,716
  • 1
  • 10
  • 13
  • I put pageLoader.unloadAndStop(); above my url requests for the swf files on loader1.fla but it doesn't work.. – Al K Jan 04 '13 at 21:00
  • try to also go into the loaded swfs (overviewvideo) and listen for the Event.UNLOAD on this.loaderInfo and call loader.unloadAndStop() and set loader=null in that file as well. – Jason Reeves Jan 04 '13 at 21:14
  • still no luck, i created a second function for event.unload with the evenlistener of loaderinfo and put loader.unloadAndStop() and set loader=null but still not doing anything – Al K Jan 04 '13 at 21:35
  • well if unloadAndStop() isn't GCing like it should (sometimes it doesn't), I would perform all of the clean up manually. first, don't load the video into the currentDomain. Clean up i.e. remove all event listeners, unload all loaders, removeChild the loaders, null it out etc. – Jason Reeves Jan 04 '13 at 22:12
  • Now i got another problem.. security sandbox violation and when i export it to html its not showing that video – Al K Jan 04 '13 at 22:26
  • use Security.allowDomain(*) and see if that fixes it. Youtube swfs load from various youtube domains. – Jason Reeves Jan 07 '13 at 21:59