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
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
Hello i'm trying to embed a youtube video into my flash project using as3.0. So far I've been able to get the video to my frame and play it. But my stage size is 500X500. So I need my video to be width:300 and height:150. I tried changing the video size but that's not worked for me. The video has it's original embedding width and height... So how can I do that?
Here is my code.
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("www.youtube.com")
loader.load(new URLRequest("http://www.youtube.com/v/yNfkNWfH6aU?version=3"));
function onLoaderInit(event:Event):void {
addChild(loader);
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(300, 150);
//player.x = stage.width/2; //puts the video horizontally centered
//player.y = stage.width/2; //puts the video vertically centered
//player.x=100;
//player.width=265;
//player.height=200;
}
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);
}
Please bear with me as I'm brand new to action script. I'm trying to build a small flash movie, that when a button is clicked in the movie, an embeded youtube video is displayed.
Building the movie is fine as I've some experience with basic flash animations, and I've followed the tutorial here to successfully embed a video on load and have it play when a button (that doesn't hide the video) is clicked.
I've tried moving the action script to load the video further down the timeline, which has caused errors, and have fiddled around with the click event to only display further down the, both have been unsuccessful though.
What I'd like to achieve is:
Short flash movie that ends with a frame that reads "Play Video", when that's clicked, the frame disappears and the video starts to play.
Any help in the right direction is appreciated.
Thanks,
Rough example:
// The player SWF file on www.youtube.com needs to communicate with your host
// SWF file. Your code must call Security.allowDomain() to allow this
// communication.
Security.allowDomain("www.youtube.com");
// This will hold the API player instance once it is initialized.
var player:Object;
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
function onLoaderInit(event:Event):void {
addChild(loader);
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, 360);
}
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);
}
more info: https://developers.google.com/youtube/flash_api_reference#Playback_controls
why this code in Action Script 3 not working when i publish it in html
its worke when i test it in flash program put when i publish it in html not working
some function not working
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.DisplayObjectContainer;
// The player SWF file on www.youtube.com needs to communicate with your host
// SWF file. Your code must call Security.allowDomain() to allow this
// communication.
Security.allowDomain("www.youtube.com");
// This will hold the API player instance once it is initialized.
var player:Object;
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
function onLoaderInit(event:Event):void {
addChild(loader);
loader.content.addEventListener("onReady", onPlayerReady);
}
function autoClick():void
{
//=========================
//Some nested children, we need to dig through a bit to get to the LargePlayButton
var safeLoader:DisplayObjectContainer = (loader.content as DisplayObjectContainer).getChildAt(0) as DisplayObjectContainer;
var videoApplication:DisplayObjectContainer = safeLoader.getChildAt(0) as DisplayObjectContainer;
var largePlayBtn:DisplayObjectContainer = videoApplication.getChildAt(6) as DisplayObjectContainer;
//=========================
//And finally dispatching our event to this button. It will think that a person has clicked it
largePlayBtn.dispatchEvent(new MouseEvent(MouseEvent.CLICK,
true,
true,
stage.stageWidth / 2,
stage.stageHeight / 2));
}
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(300, 250);
player.cueVideoById("zlOB8nPdPG8",0);
//====================================================
//As long as player is loaded we can call our function
autoClick();
}
pleas help me to solve this problem fast
I tried your code, and HTML does work.
Just that it won't work if you double click to open it, it need to open it in a webserver. Do you have Apache / MAMP / XAMMP / Appserv installed on your machine?
Is there any way to auto-click on XY stage coordinates upon when SWF is loaded?
EDIT: By the way, this is the whole code, and it is a cued youtube video. Just want to click anywhere on the cue to play it automatically after SWF loading.
Security.allowDomain("www.youtube.com");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
function onLoaderInit(event:Event):void {
addChild(loader);
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 {
trace("player ready:", Object(event).data);
player = loader.content;
player.setSize(300, 250);
player.cueVideoById("AfTCtRDsWVw",0);
player.mute();
}
function onPlayerError(event:Event):void {
trace("player error:", Object(event).data);
}
function onPlayerStateChange(event:Event):void {
trace("player state:", Object(event).data);
}
function onVideoPlaybackQualityChange(event:Event):void {
trace("video quality:", Object(event).data);
}
Yes, you should just manually dispatch your MouseEvent.CLICK Event to your stage:
var yourX:Number = 40; //Whatever you want
var yourY:Number = 40; //Whatever you want
//Make sure you have a link to the stage (usually after Event.ADDED_TO_STAGE event occured)
stage.dispatchEvent(new MouseEvent(
MouseEvent.CLICK,
true,
false,
yourX,
yourY);
If you need a certain DisplayObject to relate to this MouseEvent, you should pass an additional parameter to the MouseEvent constructor:
var yourX:Number = 40; //Whatever you want
var yourY:Number = 40; //Whatever you want
//Make sure you have a link to the stage (usually after Event.ADDED_TO_STAGE event occured)
stage.dispatchEvent(new MouseEvent(
MouseEvent.CLICK,
true,
false,
yourX,
yourY,
linkToYourRelatedDisplayObject);
==UPDATE==
Well, I've made it. A bit of "hacking" and here it is.
Your youtube player contains a safeLoader object, which contains a videoApplication, which contains a LargePlayerButton. This LargePlayerButton has a MouseEvent.CLICK event listener, so we need to dispatch out event to this button instead of dispatching it to the stage.
Here's the complete code with autoClick simulation:
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.DisplayObjectContainer;
// The player SWF file on www.youtube.com needs to communicate with your host
// SWF file. Your code must call Security.allowDomain() to allow this
// communication.
Security.allowDomain("www.youtube.com");
// This will hold the API player instance once it is initialized.
var player:Object;
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
function onLoaderInit(event:Event):void {
addChild(loader);
loader.content.addEventListener("onReady", onPlayerReady);
}
function autoClick():void
{
//=========================
//Some nested children, we need to dig through a bit to get to the LargePlayButton
var safeLoader:DisplayObjectContainer = (loader.content as DisplayObjectContainer).getChildAt(0) as DisplayObjectContainer;
var videoApplication:DisplayObjectContainer = safeLoader.getChildAt(0) as DisplayObjectContainer;
var largePlayBtn:DisplayObjectContainer = videoApplication.getChildAt(6) as DisplayObjectContainer;
//=========================
//And finally dispatching our event to this button. It will think that a person has clicked it
largePlayBtn.dispatchEvent(new MouseEvent(MouseEvent.CLICK,
true,
true,
stage.stageWidth / 2,
stage.stageHeight / 2));
}
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(300, 250);
player.cueVideoById("AfTCtRDsWVw",0);
//====================================================
//As long as player is loaded we can call our function
autoClick();
}
It was a nice exercise, cheers :)
Youtube seems to have an intelligent anti hack feature. I'm able to get the children of SafeLoader on the IDE, but on the flash player, or the web, the SafeLoader just isn't accessible, and no children after that can be controlled. This is why the code works on the IDE but not outside. Maybe it has to do with sandbox security, but maybe it's more complex.
I doubt very much that it is possible, for obvious security reasons : http://www.adobe.com/devnet/flashplayer/articles/fplayer10_uia_requirements.html