Load swf on loaded swf? - actionscript-3

I'm on a project created in Flash Builder 4.7 and Flash Professional CS6, nice.
I need the project load's a SWF inside the "preloaded SWF",
The first SWF, loads a second SWF,
This second SWF would be the "Home" of the project.
At this point, it work's perfectly. But when the "Home" try to load other external SWF, it says :
[IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2124"]
The code of the first SWF:
public class InitialSWF extends MovieClip
{
private var _loader_:Loader;
private var _applicationContent_:DisplayObject;
private var _loaderContent_:MovieClip;
private var _loaderIcon_:MovieClip;
public function InitialSWF()
{
super();
_loader_ = new Loader();
_loader_.contentLoaderInfo.addEventListener(Event.COMPLETE,_onComplete_,false,0,true);
_loader_.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,_onIoError_,false,0,true);
_loader_.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,_onProgress_,false,0,true);
_loader_.load(new URLRequest("Home.swf"));
}
private function _onComplete_(param1:Event) : void
{
_applicationContent_ = _loader_.content;
_applicationContent_.visible = true;
stage.addChild(_applicationContent_);
_applicationContent_.addEventListener("onApplicationComplete",_onApplicationComplete_,false,0,true);
_loader_.contentLoaderInfo.removeEventListener(Event.COMPLETE,_onComplete_);
_loader_.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,_onIoError_);
_loader_.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,_onProgress_);
_loader_.unload();
_loader_ = null;
}
private function _onApplicationComplete_(tmpEvt:Event) : void
{
_applicationContent_.removeEventListener("onApplicationComplete",_onApplicationComplete_);
_loaderContent_.addEventListener("loaderOut",_onLoaderOut_,false,0,true);
// do something
}
private function _onLoaderOut_(param1:Event) : void
{
_loaderContent_.removeEventListener("loaderOut",_onLoaderOut_);
_applicationContent_.visible = true;
stage.removeChild(this);
}
private function _onIoError_(tmpError:IOErrorEvent) : void
{
trace(tmpError);
}
private function _onProgress_(param1:ProgressEvent) : void
{
var _progress_:Number = Math.round(param1.bytesLoaded / param1.bytesTotal * 100);
//Do animation loading
}
And the HomeSWF:
public class SecondarySWF extends Sprite
{
private var _loader_:Loader;
private var _loaderContent_:MovieClip;
private var _loaderIcon_:MovieClip;
private var _applicationContent_:DisplayObject;
public function SecondarySWF()
{
this.addEventListener(Event.ADDED_TO_STAGE,this._GoLogin_,false,0,true);
}
public function _GoLogin_(tmpEvent:Event)
{
_loader_ = new Loader();
_loader_.contentLoaderInfo.addEventListener(Event.COMPLETE,_onComplete_,false,0,true);
_loader_.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,_onIoError_,false,0,true);
_loader_.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,_onProgress_,false,0,true);
_loader_.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
_loader_.load(new URLRequest("SecondarySWF.swf"));
}
private function httpStatusHandler(event:HTTPStatusEvent):void {
trace(event);
}
private function _onComplete_(param1:Event) : *
{
_applicationContent_ = _loader_.content;
_applicationContent_.visible = true;
stage.addChild(_applicationContent_);
_applicationContent_.addEventListener("onApplicationComplete",_onApplicationComplete_,false,0,true);
_loader_.contentLoaderInfo.removeEventListener(Event.COMPLETE,_onComplete_);
_loader_.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,_onIoError_);
_loader_.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,_onProgress_);
_loader_.unload();
_loader_ = null;
this.removeEventListener(Event.ADDED_TO_STAGE,this._GoLogin_);
}
private function _onApplicationComplete_(param1:Event) : void
{
_applicationContent_.removeEventListener("onApplicationComplete",_onApplicationComplete_);
_loaderContent_.addEventListener("loaderOut",_onLoaderOut_,false,0,true);
// ..
}
private function _onLoaderOut_(param1:Event) : void
{
_loaderContent_.removeEventListener("loaderOut",_onLoaderOut_);
//_applicationContent_.visible = true;
//stage.removeChild(this);
}
private function _onIoError_(tmpError:IOErrorEvent) : void
{
trace(tmpError);
}
private function _onProgress_(param1:ProgressEvent) : void
{
var _progress_:Number = Math.round(param1.bytesLoaded / param1.bytesTotal * 100);
// ..
}
}
ConsoleChromeSWF <-This is an image of the Google console.log, and catch this:
start InitialSWF
Load HomeSWF
Complete loaded of HomeSWF
Start HomeSWF
The link of the Secondary SWF (censored/hidden from public)
Load SecondarySWF
ERROR
I don't know why the Secondary SWF is 100% loaded but return an error... Regards!

Related

ActionScript 3.0 How to call SoundManager to all classes

i have 3 classes. the SoundManager.as, MainMenu.as, and OnGame.as.
How can I call SoundManager on MainMenu.as and OnGame.as properly?
I tried:
MainMenu.as:
var sound:SoundManager = new SoundManager();
OnGame.as:
var sound:SoundManager = new SoundManager();
but when i turn off the bgmusic on OnGame.as, the bgmusic on MainMenu doesn't turn off.
Sorry for my bad english and explanation. please help me.
//edited
When i call function 'MUTE' from the SoundManager in onGame.as and go back to mainmenu, the bgmusic in MainManu.as is not muted. help please me.
SoundManager.as
public static var mVolume:SoundTransform = new SoundTransform();
public static var mChannel:SoundChannel = new SoundChannel();
public static var mPosition:Number;
public static var music:Sound = new Sound();
public static var Music:Boolean = true;
public function LOADMUSIC():void {
if(Music){
UNMUTE();
}else {
MUTE();
}
music.addEventListener(Event.COMPLETE, LOADMUSIC);
mChannel = music.play();
mChannel.addEventListener(Event.SOUND_COMPLETE, ONCOMPLETE);
}
public function ONCOMPLETE(e:Event):void {
if(DataBase.music){
UNMUTE();
}else{
MUTE();
}
e.currentTarget.removeEventListener(Event.SOUND_COMPLETE, ONCOMPLETE);
LOADMUSIC();
}
public function REMOVE_MUSIC():void{
try{
mChannel.stop();
music = null;
}catch(e:Error) {}
}
public function MUTE():void {
mVolume.volume = 0;
mChannel.soundTransform = mVolume;
}
public function UNMUTE():void {
mVolume.volume = 1;
mChannel.soundTransform = mVolume;
}
MainMenu.as
var sound:SoundManager;
btn_music.addEventListener(TouchEvent:TOUCH_END, MUSIC);
public MainMenu(sound:SoundManager){
this.sound = sound;
sound.REMOVE_MUSIC();
SoundManager.music = new BackgroundMusic01();
sound.LOADMUSIC();
}
private function MUSIC(e:TouchEvent):void {
if(SoundManager.Music){
SoundManager.music = false;
sound.MUTE();
}else {
SoundManager.Music = true;
sound.UNMUTE();
}
}
OnGame.as
var sound:SoundManager;
btn_music.addEventListener(TouchEvent:TOUCH_END, MUSIC);
public OnGame(sound:SoundManager){
this.sound = sound;
sound.REMOVE_MUSIC();
SoundManager.music = new BackgroundMusic02();
sound.LOADMUSIC();
}
private function MUSIC(e:TouchEvent):void {
if(SoundManager.Music){
SoundManager.music = false;
sound.MUTE();
}else {
SoundManager.Music = true;
sound.UNMUTE();
}
}
There's no problem in changing the background music. When i mute the bgmusic in MainMenu using MainMenu btn_music it works, it works also in OnGame. But if it is from OnGame to MainMenu or MainMenu to Ongame, the bgmusic is not muted . I don't see what's wrong. please help me. sorry for my bad english.
Singleton or some other static (global) access is one easy way to do it. But just to add an alternative solution, according to some a "better way" is to use dependency injection. A simple example of this for your situation could look like this:
First, in your MainMenu and OnGame class you add a constructor argument (effectively declaring a dependency) of a SoundManager instance:
public class MainMenu {
private var sound:SoundManager;
public function MainMenu(sound:SoundManager){
this.sound = sound;
}
}
public class OnGame {
private var sound:SoundManager;
public function OnGame(sound:SoundManager){
this.sound = sound;
}
}
Then in a higher level class, you can create a single SoundManager and pass it into the classes that need it:
public class Main {
private var sound:SoundManager;
public function Main(){
sound = new SoundManager();
}
private function showMenu():void {
var menu:MainMenu = new MainMenu(sound);
addChild(menu);
}
private function showGame():void {
var game:OnGame = new OnGame(sound);
addChild(game);
}
}
The end result is that you have a single SoundManager instance being re-used between various classes.
There are several ways to do it, one of them is to use a Singleton class.
Follow an example:
package
{
public class CustomSoundManager
{
private static var _instance:CustomSoundManager;
public function CustomSoundManager()
{
if (_instance)
{
throw new Error('CustomSoundManager... use getInstance()');
}
_instance = this;
}
public static function getInstance():CustomSoundManager
{
if (!_instance)
{
new CustomSoundManager();
}
return _instance;
}
public function soundOn():void
{
// your logic to turn the sound on
}
public function soundOff():void
{
// your logic to turn the sound off
}
}
}
So, doesn't matter where (e.g. MainMenu.as, OnGame.as), you can use just these methods:
CustomSoundManager.getInstance().soundOn();
CustomSoundManager.getInstance().soundOff();
Because i can't see what's wrong in my code. Since I only got 1 channel in my game, i used SoundMixer to mute and unmute the music background.
import flash.media.SoundMixer;
...
...
public function MUTE():void {
mVolume.volume = 0;
SoundMixer.soundTransform = mVolume;
}
public function UNMUTE():void {
mVolume.volume = 1;
SoundMixer.soundTransform = mVolume;
}
thanks.

Object Loading Issue

I am developing an application that consists of several different objects working together. Everything seems to work great, however, when I play this on a web server I notice the graphics and assets that are being loaded in from an external source are taking some time to load I'm not really sure what is going on I was hoping someone might provide some insight. Example, sometimes the graphic assets will not load at all, but audio seems to be loading in ok. Here is an example of my image loading class:
GFXReg.as
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.net.URLRequest;
import flash.display.Loader;
import flash.display.Sprite;
import flash.text.TextField;
public class GFXReg extends Sprite {
private var mc: MovieClip = new MovieClip();
private var loader: Loader = new Loader();
private var setW: Number;
public var setH: Number;
public var theH: Number;
private var bool: Boolean = false;
public function GFXReg(setSize: Boolean, W: Number, H: Number) {
bool = setSize;
if (bool) {
setW = W;
setH = H;
}
}
private function loadData(e: Event) {
if(loader.contentLoaderInfo.bytesLoaded == loader.contentLoaderInfo.bytesTotal){
addChild(loader);
}else{
var text:TextField = new TextField();
text.text = "Loading..."
addChild(text);
}
if (bool) {
loader.width = setW;
loader.height = setH;
}
}
public function theData(file: String): void {
loader.load(new URLRequest(file));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadData);
}
public function getBytes(str:String):int{
var num:int = 0;
switch(str){
case "loaded":
num = loader.contentLoaderInfo.bytesLoaded;
break;
case "total":
num = loader.contentLoaderInfo.bytesTotal;
break;
}
return num;
}
public function removeData():void{
loader.unloadAndStop(false);
trace("unload?");
}
private function unloadData(e:Event):void{
}
}
}
Main.as Sections(This loads in all the appropriate sections when prompted):
public function Main() {
xmlLoader = new XMLReg("config.xml", processXML);
}
private function processXML(e: Event): void {
theXML = new XML(e.target.data);
dir = theXML.MASTER.#DIRECTORY;
//BACKGROUND
bgGFX.theData(dir + theXML.MAINBG.#IMG);
//INITIALIZE
add(bgGFX,intro);
//INTRO WAS INSTANTIATED IN THE BEGINNING OF THIS CLASS
intro.start();
/*start method adds objects to stage, to test as a solution*/
addChildAt(header, numChildren);
//...
Also in my Main.as class I have a private method transition which loads in the appropriate sections after the previous sections have been completed these assets usually take a few seconds to load in I've noticed when working on a web server.
private function transition(e: Event): void {
//If intro is on the stage instantiate a new QuestionAnswer Object
if (intro.stage) {
header.enableMenu(true);
qa = new QuestAnswer(feedBool,nameCounter,nameVar);
qa.addEventListener("unload", transition);
qa.addEventListener("addFeed", setFeedFalse);
qa.addEventListener("addFeedTrue", setFeedTrue);
qa.addEventListener("enableHelp",enableHelp);
qa.addEventListener("getName",getName);
addChildAt(qa, numChildren-1);
remove(intro);
} else if (qa.stage) {
//If QuestionAnswer is on the Stage instantiate a new Results Object
header.enableMenu(true);
header.enableHelp(false);
results = new Results(qa.resultBundle());
results.addEventListener("unload", transition);
results.addEventListener("addFeed", setFeedFalse);
results.addEventListener("addFeedTrue", setFeedTrue);
results.addEventListener("setName",setName);
addChildAt(results, numChildren-1);
remove(qa);
} else if (results.stage) {
//If Results is on the stage loop back and instantiate a new QuestionAnswer Object
header.enableMenu(true);
header.enableHelp(false);
intro.enableAsset(true);
qa = new QuestAnswer(feedBool,nameCounter,nameVar);
qa.addEventListener("unload", transition);
qa.addEventListener("addFeed", setFeedFalse);
qa.addEventListener("addFeedTrue", setFeedTrue);
addChildAt(qa, numChildren-1);
trackAsset = true;
remove(results);
}
}

Get data from two object in OOP AS3

I have a Car class like this
public class Car extends Sprite
{
private var car :Sprite;
private var buttonCar :Sprite;
private var _kmh :int;
public function Car()
{
makeCar();
makeButtonCar();
}
private function makeCar() : void
{
car = new Sprite();
car.graphics.beginFill(0x0000FF, 1);
car.graphics.drawRect(0, 0, 100, 50);
car.x = 100;
this.addChild(car);
}
private function makeButtonCar() : void
{
buttonCar = new Sprite();
buttonCar.graphics.beginFill(0xFF0000, 1);
buttonCar.graphics.drawCircle(0, 0, 25);
buttonCar.x = 300;
this.addChild(buttonCar);
buttonCar.addEventListener(MouseEvent.MOUSE_DOWN, KMH);
}
private function KMH(e:MouseEvent) : void
{
_kmh++;
trace("kmh: "+_kmh);
}
}
in the Main class I make newCar from Car class, newCar1 and newCar2.
public class OOPVariable extends Sprite
{
private var newCar1  :Car;
private var newCar2  :Car;
public function OOPVariable()
{
newCar1 = new Car();
addChild(newCar1);
newCar2 = new Car();
newCar2.y = 100; 
addChild(newCar2);
super();
}
}
I want get total of variable _kmh from all object newCar when one of the button from newCar clicked and mouse event still in Car class.
you could either do what Nathan said, or you can make your kmh variable public;
that way you can access it through a mouseEvent.
first, you'll have to import flash.utils.getQualifiedClassName.
then you can use a for() loop to get all of the cars on stage, and trace the total KMH.
// traces out the total KMH and num of cars on stage
// your car class should keep kmh updated
private function getTotalKMH(e:MouseEvent) :void
{
var totalCars:int = 0;
var KMH:int = 0;
for (var i:int = 0; i < stage.numChildren-1; i++)
{
if (getQualifiedClassName(e.currentTarget) == "Car")
{
++totalCars;
KMH += getChildByIndex(i).kmh; // ".kmh" is the variable in your car class
}
}
trace("Total Cars: " + totalCars + "\nTotal KMH: " + KMH);
}
of course, you can do more than just trace it.
you can pass it to a class scope variable or a function if you need to.
thanks all for your reply, I'm using custom event and dispatch event like what Nathan said :D
this is Main class, carListener method summing all kmh from all car when button car clicked
package
{
import flash.display.Sprite;
import support.CarEvent;
import support.CarObject;
public class OOPCar extends Sprite
{
private var newCar1 :CarObject;
private var newCar2 :CarObject;
private var totalKmh :int = 0;
private var currentName :String;
public function OOPCar()
{
newCar1 = new CarObject();
newCar1.name = "car1";
newCar1.setKmh(2);
addChild(newCar1);
newCar1.addEventListener(CarEvent.UPDATE, carListener);
newCar2 = new CarObject();
newCar2.name = "car2";
newCar2.setKmh(4);
addChild(newCar2);
newCar2.addEventListener(CarEvent.UPDATE, carListener);
newCar2.y = 100;
}
private function carListener(e:CarEvent) : void
{
trace("kmhCar: "+e.kmhCar);
totalKmh += e.kmhCar;
trace("totalKmh: "+totalKmh);
currentName = e.currentTarget.name;
}
}
}
class for make a car
package support
{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class CarObject extends Sprite
{
private var car :Sprite;
private var buttonCar :Sprite;
private var _kmh :int;
public function CarObject()
{
makeCar();
makeButtonCar();
}
private function makeCar() : void
{
car = new Sprite();
car.graphics.beginFill(0x0000FF, 1);
car.graphics.drawRect(0, 0, 100, 50);
car.x = 100;
this.addChild(car);
}
private function makeButtonCar() : void
{
buttonCar = new Sprite();
buttonCar.graphics.beginFill(0xFF0000, 1);
buttonCar.graphics.drawCircle(0, 0, 25);
buttonCar.x = 300;
this.addChild(buttonCar);
buttonCar.addEventListener(MouseEvent.MOUSE_DOWN, update);
}
public function setKmh(kmh:int) : void
{
_kmh = kmh;
}
public function update(e:MouseEvent) : void
{
dispatchEvent(new CarEvent(CarEvent.UPDATE, true, false, _kmh));
}
}
}
and this is my custom event
package support
{
import flash.events.Event;
public class CarEvent extends Event
{
public static const UPDATE:String = "update";
public var kmhCar :int;
public function CarEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, kmhCar:int = 0)
{
super(type, bubbles, cancelable);
this.kmhCar = kmhCar;
}
public override function clone() : Event
{
return new CarEvent(type, bubbles, cancelable, kmhCar);
}
public override function toString():String
{
return formatToString("CarEvent", "type", "bubbles", "cancelable", "eventPhase", "kmhCar");
}
}
}

Definition fl.video.FLVPlayback could not be found

I'm stumped. I have two flash files I'm authoring.
File A has a MovieClip on stage that has a linkage to a class in which I import fl.video.FLVPlayback
File B also attempts to import fl.video.FLVPlayback.
File B throws a COMPILE TIME error that it cannot locate the definition for fl.video.FLVPlayback. I'm noticing that my FlashDevelop also offers no syntax highlighting for that line.
Both are exporting for the same version of FlashPlayer (10). Both are being authored on the same platform, the same software (CS4).I have not messed with any Publish settings, other than that File B is associated with a Document Class.
Of interest may be that File A will eventually be loaded into File B, into the context of File B.
What is up? I have no idea where to even start looking.
Thanks in advance.
If you're not using the FLVPlayback component (dragged from the component library onto the stage), then Flash does not have access to the fl package out of the box for publishing.
You would have to include either the component source folder or .swc on your class path (source folder would go in the "Source Path" tab of your as3 publish settings, .swc in the "Library Path" tab) in order for your class to work.
The source folder is:
C:\Program Files (x86)\Adobe\Adobe Flash CS4\Common\Configuration\Component Source\ActionScript 3.0\FLVPlayback
The .swc is in the directory:
C:\Program Files (x86)\Adobe\Adobe Flash CS4\Common\Configuration\Components\Video
The swc is probably easier to include as you can copy and paste the .swc directly into your project folder if you like.
Building on Sapptime's answer, I would like to add that you can create different profiles under Publish Settings.
So you can make a profile which includes the FLVPlayback component by importing the .swc file and use that profile when you need to work with the FLVPlayer. Adds about 100 KB to the project.
This way you don't need a FLVPlayback component in your library or on your stage. Instead, you can import the FLVPlayback class like any other class in your project and make instances of FLVPlayback in your actionscript code.
//import:
import fl.video.FLVPlayback;
//Instantiate:
private var player:FLVPlayback = new FLVPlayback();
I have added a Videoplayer.as class (because I can't find a way to attach it) I made for a project and stripped it quick and dirty for some additional content, but it should work :) Feel free to use it as is, modify it or get some inspiration.
Put Videoplayer.as in the src folder of your project and make a new instance of it. Use the setters to control it.
//Instantiate
var MyPLayer:Videoplayer = new Videoplayer();
//Use setters
MyPLayer.SetVideopath = path to flv file;
MyPLayer.SetVideoAutoplay = true; // or false
//... and so on
// add to displaylist
this.addChild(MyPlayer);
// Load video
MyPlayer.Load();
// start playing
MyPlayer.Play();
and here is the Videoplayer class...
package {
import fl.video.*;
import flash.events.*;
import flash.display.Sprite;
import flash.display.Shape;
public class Videoplayer extends Sprite {
// VIDEO
private var player:FLVPlayback = new FLVPlayback();
private static var videoPath:String="";
private var w:Number = 1280;
private var h:Number = 720;
private var vol:Number = 0;
private var autoplay:Boolean = false;
private var autorewind:Boolean = false;
private var Loop:Boolean = false;
private var bgcolor:uint = 0x000000;
private var HasError:Boolean=false;
private var playerid:Number;
private var SeekSecToStop:Number=0;
private var BufferTime:Number=0;
private var videoBG:Shape;
// ===============================================================================================
// CONSTRUCTOR
// ===============================================================================================
public function Videoplayer() {
super();
trace("Videoplayer");
this.addChild(player);
player.addEventListener(VideoEvent.STATE_CHANGE, VidState, false, 0, true);
player.addEventListener(VideoEvent.READY, VidReady, false, 0, true);
player.addEventListener(VideoEvent.AUTO_REWOUND, VidRewinded, false, 0, true);
player.addEventListener(VideoEvent.STOPPED_STATE_ENTERED, VidStopped, false,0,true);
}
// ===============================================================================================
// SET VIDEO PROPS
// ===============================================================================================
private function setVidProps():void {
player.name = "player";
player.skinBackgroundColor = getVideoBGcolor;
player.skinBackgroundAlpha = 0;
player.registrationX = 0;
player.registrationY = 0;
player.setSize(getVideoWidth,getVideoHeight);
player.scaleMode = "maintainAspectRatio"; // exactFit, noScale, maintainAspectRatio
//player.fullScreenTakeOver = false;
player.isLive = false;
player.bufferTime = BufferTime;
player.autoRewind = getVideoAutorewind;
player.volume = vol;
}
// ===============================================================================================
// LOAD
// ===============================================================================================
public function Load():void {
trace("Load");
setVidProps();
player.source = getVideopath;
}
// ===============================================================================================
// PLAY
// ===============================================================================================
public function Play():void {
player.playWhenEnoughDownloaded();
UnMute();
}
public function Pause():void {
player.pause();
}
public function Stop():void {
//player.seek(SeekSecToStop);
player.stop();
//player.pause();
}
public function SeekAndStop():void {
player.seek(SeekSecToStop);
player.pause();
}
public function SeekAndPlay(n:Number=0):void {
player.seek(n);
Play();
}
public function Fullscreen():void {
//player.fullScreenTakeOver = true;
//player
}
public function Mute():void {
player.volume = 0;
}
public function UnMute():void {
player.volume = 1;
}
public function Volume(n:Number):void {
player.volume=n;
}
// ===============================================================================================
// VidReady
// ===============================================================================================
private function VidReady(e:Event):void {
trace("VidReady");
//player.removeEventListener(VideoEvent.READY, VidReady);
player.fullScreenTakeOver = false;
if (autoplay) {
player.autoPlay = autoplay;
Play();
} else {
player.play();
SeekAndStop();
}
dispatchEvent(new VideoEvent(VideoEvent.READY));
}
// ===============================================================================================
// VidStopped
// ===============================================================================================
private function VidStopped(e:Event):void {
trace("VidStopped");
//dispatchEvent(new VideoEvent(VideoEvent.STOPPED));
if(Loop) {
//SeekAndPlay();
Play();
} else {
dispatchEvent(new VideoEvent(VideoEvent.STOPPED_STATE_ENTERED));
}
}
// ===============================================================================================
// VidRewinded
// ===============================================================================================
private function VidRewinded(e:Event):void {
trace("VidRewinded");
}
// ===============================================================================================
// VidState
// ===============================================================================================
private function VidState(e:Event):void {
var flvPlayer:FLVPlayback = e.currentTarget as FLVPlayback;
//Log("VideoState 1 : "+flvPlayer.state);
if (flvPlayer.state==VideoState.CONNECTION_ERROR) {
trace("FLVPlayer Connection Error! -> path : "+flvPlayer.source);
//dispatchEvent(new VideoEvent(VideoEvent.CONNECTION_ERROR));
HasError=true;
//CleanUp();
} else if (flvPlayer.state==VideoState.BUFFERING) {
trace("BUFFERING");
} else if (flvPlayer.state==VideoState.DISCONNECTED) {
trace("DISCONNECTED");
} else if (flvPlayer.state==VideoState.LOADING) {
trace("LOADING");
} else if (flvPlayer.state==VideoState.PAUSED) {
trace("PAUSED");
} else if (flvPlayer.state==VideoState.RESIZING) {
trace("RESIZING");
} else if (flvPlayer.state==VideoState.REWINDING) {
trace("REWINDING");
} else if (flvPlayer.state==VideoState.SEEKING) {
trace("SEEKING");
} else if (flvPlayer.state==VideoState.PLAYING) {
trace("PLAYING");
} else if (flvPlayer.state==VideoState.STOPPED) {
trace("STOPPED");
//flvPlayer.pause();
} else if (flvPlayer.state==VideoState.RESIZING) {
trace("RESIZING");
}
}
// ===============================================================================================
// SETTERS & GETTERS
// ===============================================================================================
public function set SetPlayerId(n:Number):void {
playerid=n;
}
public function get getPlayerId():Number {
return playerid;
}
public function set SetSeekSecToStop(n:Number):void {
SeekSecToStop=n;
}
public function get getSeekSecToStop():Number {
return SeekSecToStop;
}
public function set SetVideoLoop(b:Boolean):void {
Loop = b;
}
public function get getVideoLoop():Boolean {
return Loop;
}
public function set SetVideoAutorewind(b:Boolean):void {
autorewind = b;
}
public function get getVideoAutorewind():Boolean {
return autorewind;
}
public function set SetVideoAutoplay(b:Boolean):void {
autoplay = b;
}
public function get getVideoAutoplay():Boolean {
return autoplay;
}
public function set SetVideopath(s:String):void {
videoPath = s;
}
public function get getVideopath():String {
return videoPath;
}
public function set SetVideoWidth(n:Number):void {
w = n;
}
public function get getVideoWidth():Number {
return w;
}
public function set SetVideoHeight(n:Number):void {
h = n;
}
public function get getVideoHeight():Number {
return h;
}
public function set SetVideoBGcolor(n:uint):void {
bgcolor = n;
}
public function get getVideoBGcolor():uint {
return bgcolor;
}
public function get getPlayerState():String {
return player.state;
}
public function get GetHasError():Boolean {
return HasError;
}
}
}
You need to make sure that the FLVPlayback component is present in you library and exported for ActionScript (which should be the default setting).
To add it to the library, simply open the Components panel (Window -> Components) and expand the group named Video and drag FLVPlayback in your library. No need to put it on the stage.
It should be exported by default as "fl.video.FLVPlayback".
Cheers

Facebook Actionscript and IE

I'm trying to use the Facebook Actionscript graph api but I seem to be having problems in IE (other browsers like chrome and firefox seem okay so far).
From what i can tell, it's logging in fine and returning the user id but when i do a lookup on that user with Facebook.api(_user, handleUserRequest); I get an error.
Is there any known problems with the Facebook Actionscript graph api that affects IE only?
thanks
ob
Per request - the error is as follows:
[IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: https://graph.facebook.com/100002210990429?access%5Ftoken=205690086123032%7C2%2EUzvN3mFr07kPAecZ7qN1Rg%5F%5F%2E3600%2E1303135200%2E1%2D100002210990429%7Cz9L%5Fc26QKCc6cs2g5FClG%5FBsoZg"]
This if this url is pasted into chrome it works just fine, but IE returns 'unable to download XXXXXXXX from graph.facebook.com'
best
obie
the code that I'm using is as follows:
package com.client.facebookgame.services
{
import com.client.facebookgame.services.events.FacebookServiceEvent;
import com.facebook.graph.data.FacebookSession;
import com.facebook.graph.Facebook;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.TimerEvent;
import flash.external.ExternalInterface;
import flash.net.URLRequestMethod;
import flash.utils.Timer;
import uk.co.thereceptacle.utils.Debug;
/**
* Facebook Service
*/
public class FacebookService extends EventDispatcher
{
// constants
public static const API_KEY : String = "XXXXXX";
public static const PERMISSIONS : String = "read_stream,publish_stream,user_likes";
public static const FB_REDIRECT_URL : String = "http://apps.facebook.com/appname/";
public static const LOGGED_IN : String = "loggedin";
public static const LOGGED_IN_ON_FB : String = "loggedinonfacebook";
public static const LOGGED_OUT : String = "loggedout";
public static const LOGGED_OUT_ON_FB : String = "loggedoutonfacebook";
public static const TIMEOUT_COUNT : int = 10;
public static const TIMER_DELAY : int = 3 * 1000;
// properties
private var _user : String;
private var _topUrl : String;
private var _currentState : String;
private var _timer : Timer;
private var _timerCount : int;
public var postObject : Object;
// constuctor
public function FacebookService()
{
if (ExternalInterface.available) _topUrl = ExternalInterface.call("top.location.toString");
Debug.log("facebook init", this);
Facebook.init(API_KEY, handleLogin);
startTiming();
currentState = _topUrl ? LOGGED_OUT : LOGGED_OUT_ON_FB;
}
// methods
public function login():void
{
Facebook.login(handleLogin, { perms: PERMISSIONS } );
}
public function logout():void
{
Facebook.logout(handleLogout);
}
public function selectUserFriendsWithAppRequestDialogue(message:String, dialogueType:String = "iframe", optionalPostObject:Object = null):void
{
this.postObject = optionalPostObject;
Facebook.ui("apprequests", { message:message }, handleAppRequest, dialogueType);
}
public function checkIfUserLikesApp():void
{
Facebook.api(_user + "/likes", handleLikes);
}
private function startTiming():void
{
if (_timer) clearTimer();
_timer = new Timer(TIMER_DELAY, TIMEOUT_COUNT);
_timer.addEventListener(TimerEvent.TIMER, handleTimerEvents);
_timer.addEventListener(TimerEvent.TIMER_COMPLETE, handleTimerEvents);
_timer.start();
}
private function clearTimer():void
{
_timer.stop();
_timer.removeEventListener(TimerEvent.TIMER, handleTimerEvents);
_timer.removeEventListener(TimerEvent.TIMER_COMPLETE, handleTimerEvents);
_timer = null;
_timerCount = 0;
}
// event handlers
private function handleLogin(success:Object, fail:Object):void
{
if (_timer) clearTimer();
if (success)
{
Debug.log(success, this);
_user = success.uid;
currentState = _topUrl ? LOGGED_IN : LOGGED_IN_ON_FB;
Facebook.api("/" + _user, handleGetUser);
}
else if (!success && !_topUrl)
{
ExternalInterface.call("redirect", API_KEY, PERMISSIONS, FB_REDIRECT_URL);
}
}
private function handleGetUser(success:Object, fail:Object):void
{
Debug.log(success + ", " + fail, this);
if (success) dispatchEvent(new FacebookServiceEvent(FacebookServiceEvent.GET_USER_COMPLETE, success));
else dispatchEvent(new FacebookServiceEvent(FacebookServiceEvent.GET_USER_FAIL, fail, true));
}
private function handleAppRequest(result:Object):void
{
if (postObject)
{
for (var i:int = 0; i < result.request_ids.length; i++)
{
var requestID:String = result.request_ids[i];
Facebook.api("/" + requestID, handleRequestFriends);
}
}
}
private function handleRequestFriends(success:Object, fail:Object):void
{
if (success)
{
var friendID:String = success.to.id;
Facebook.api("/" + friendID + "/feed", handleSubmitFeed, postObject, URLRequestMethod.POST);
}
else
{
Debug.log(fail, this);
}
}
private function handleLikes(success:Object, fail:Object):void
{
if (success)
{
for (var i:int = 0; i < success.length; i++)
{
Debug.log("compare " + success[i].id + " with key: " + API_KEY, this);
if (success[i].id == API_KEY)
{
Debug.log("found that user liked this app!!!", this, true);
dispatchEvent(new FacebookServiceEvent(FacebookServiceEvent.USER_LIKES_APP, { userLikesApp:true } ));
return;
}
}
dispatchEvent(new FacebookServiceEvent(FacebookServiceEvent.USER_LIKES_APP, { userLikesApp:false } ));
}
else
{
Debug.log(fail, this, true);
}
}
private function handleLogout(obj:*):void
{
currentState = _topUrl ? LOGGED_OUT : LOGGED_OUT_ON_FB;
}
private function handleSubmitFeed(success:Object, fail:Object):void
{
if (success) dispatchEvent(new FacebookServiceEvent(FacebookServiceEvent.FEED_SUBMITTED, success));
else dispatchEvent(new FacebookServiceEvent(FacebookServiceEvent.FEED_FAIL, fail, true));
}
private function handleTimerEvents(e:TimerEvent):void
{
switch (e.type)
{
case TimerEvent.TIMER :
_timerCount ++;
Debug.log("facebook init attempt " + _timerCount, this);
Facebook.init(API_KEY, handleLogin);
break;
case TimerEvent.TIMER_COMPLETE :
clearTimer();
dispatchEvent(new FacebookServiceEvent(FacebookServiceEvent.GET_USER_FAIL));
break;
}
}
// accessors / mutators
public function get currentState():String { return _currentState; }
public function set currentState(value:String):void
{
if (_currentState != value)
{
_currentState = value;
dispatchEvent(new FacebookServiceEvent(FacebookServiceEvent.STATE_UPDATE));
}
}
}
}
Thanks very much
ob
i found the answer on the facebook actionscript issues list:
http://code.google.com/p/facebook-actionscript-api/issues/detail?id=197
I was also trying to find a solution
but the only one is to publish it with
flash player 10
fixed the problem for me
I was facing same issue.Main reason of this issue is Flash Player version.
Use Flash Player 10+ FaceBookGraphApi SWC file is compatible with Flash Player 10.
This solution is only for who are using swc from GraphAPI_Examples_1_6_1