I'm trying to make it so once my my video ends the player will be moved onto a new SWF.
Here's the code I created
import fl.video.VideoEvent;
stop();
BackgroundVid.addEventListener(Event.COMPLETE, Menu_Screen);
function Menu_Screen(event:MouseEvent):void
{
var Menu_Screen_Loader = new Loader();
Menu_Screen_Loader.load(new URLRequest("Menu_Screen.swf"));
addChild(Menu_Screen_Loader);
}
Can't figure out why it's not booting properly.
Ok, first of all fix the mistake in the event handler. You are saying that the Event expected is a MouseEvent, where as it will in fact be a plain old Event.
Then if it still doesn't work, you'll need to furnish a bit more info regarding what isn't happening. What do you mean by booting properly. Is your video playing?
Related
I have loaded an external SWF to my timeline using a common loader method. The SWF is Jwplayer and it is polling a live rtmp stream. Here is the snippet I used to load it successfully.
var c4:Loader = new Loader();
var c4req:URLRequest = new URLRequest("player.swf");
var c4flashvars:URLVariables = new URLVariables();
c4flashvars.streamer = "rtmp://myserver";
c4flashvars.file = "live"
c4req.data = c4flashvars;
c4.load(c4req);
addChild(c4)
Now, the player loads fine. It begins to poll a live stream, too. However, no matter what I try I cannot remove this child from the stage. I have tried the following:
removeChild(c4);
c4.unloadAndStop();
For testing, I am calling these from a timer/event listener/function combo. I traced it to make sure it was being fired, and it is. However the player just sits there on the stage and refuses to leave. Output isn't throwing any errors. I half suspect that because it's polling a live stream that the loader never sees the external SWF as fully loaded. But that's just a hunch.
The overall scope of this little project is to load the player, check for an event, and re-load the player (unload, and reload). If anyone could help me understand this, get past this, or is feeling generous enough to show me the light; I'd appreciate it greatly. I've put a solid day into messing around with this and searching. I'm just not grasping something. Thanks!
I've read the previous posts of SO and it seems that some people's had the same issue as me - but none came up with a solution that helped my problem :)
I've designed 3 games that are their own SWF file, and I'm trying to load them upon a keypress in a container-program, sort of :).
I'm getting the TypeError 1009 null reference on all my SWF files though :( and they run perfectly when I load them from Windows. I've tried loading a SWF made by someone else, and that did work. So maybe my way of designing flash games is a bit off?
Everything takes place in frame 1 - that's maybe something that's off.
My loader code is:
stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeysDown);
function loaderFunction(swfFile:String):void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest(swfFile));
}
function onComplete(e:Event):void {
var movie:* = LoaderInfo(e.currentTarget).content;
//Adding content to the stage
stage.addChild(movie);
}
function reportKeysDown(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.NUMBER_1) {
stage.removeChildren(1);
loaderFunction("Card.swf");
}
if(event.keyCode == Keyboard.NUMBER_2){
stage.removeChildren(1);
loaderFunction("Puzzle.swf");
}
if(event.keyCode == Keyboard.NUMBER_3){
stage.removeChildren(1);
loaderFunction("BallGame.swf");
}
}
And the error is
TypeError: Error #1009: Cannot access a property or method of a null
object reference. at BallGame_fla::MainTimeline/frame1()
(I get these for everyone of the SWF's)
I'm not sure how to debug those games I'm loading since there's nothing wrong when I play separately.
Any ideas :)? Thanks!
Edit:
It started telling me which lines were acting up, and it seems to be the keyboard-listener, at least for one of the games. I'm reading keyboard into much like I am with the loader swf.
stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);
Solution-Edit:
The problem is that the loaded SWFs are using the "stage" property, and when they're loaded into another SWF the stage isn't theirs to own. That's what's causing the errors :) #BotMaster
Solution-Solution Edit:
You can still look for keyboard inputs (like I was doing) in a nested SWF, if you're using the
Event.ADDED_TO_STAGE
Like this, for instance :)
this.addEventListener(Event.ADDED_TO_STAGE, onAdded);
function onAdded(e:Event):void{
trace("added");
stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);
}
#null
stage only becomes available (it's not null) when the DisplayObject is added to the display list.
The only exception to that rule is the main file or the first file that is opened in the flash player.
That's why each of your games plays fine individually.
You should only use stage property if it is available. To do this, listen for the Event.ADDED_TO_STAGE event. This will be dispatched when something is added to the stage. In the handler function, you can safely use stage.
You still should add the listener to the stage but only if it is available to you.
Please read the documentation about addChild(). You should basically never add anything to stage. In general, take a look at the basics of the display list and how it works.
hai i want play two swf files in my action script project.In this two files one swf file works on the detection face in front of the system.Other swf plays the flv file.when face is detected player must be stooped if not player must be plays the flv file.
I know how to load the swf file but i cant handle the functionality regarding starting and stoping player.
the snippet of code shows how can i load external swf file .and i will explain each line of code in comments
public function videos(view:Sprite)
{
this.box = view;//IT GETS Sprite object from other class because of need to display the player also.
request = new URLRequest("Untitled-1.swf");
currentSWF=new MovieClip();
loader= new Loader();
loader.load(request);
box.addChild(loader);
currentSWF = MovieClip(loader.content);
loader.addEventListener(Event.COMPLETE,loadComplete);
//addChild(loader);
currentSWF.gotoAndPlay(1);//when i put this line of code in comments it plays the external swf also.
}
I hope u understand my doubt .can any one explain how to handle my things .i am new to this action script.please help me
Loaded files automatically play, unless you tell them explicitely not to. You’ll have to listen to the Event.INIT event, and stop the movie there:
loader.AddEventListener(Event.INIT, initLoader);
function initLoader (event:Event)
{
MovieClip(event.currentTarget.content).stop();
}
This will stop the movie before it is attached to the stage, and before it starts playing—so it won’t do that unless you start it again.
Note that you shouldn’t access loader.content in any way before the INIT or COMPLETE events, as it’s very likely that the content isn’t loaded then. As such you should put all your manipulating actions into the COMPLETE event:
box.addChild(loader);
loader.addEventListener(Event.COMPLETE, loadComplete);
function loadComplete (event:Event)
{
// Now it’s safe to access the `content` member:
currentSWF = MovieClip(loader.content);
// Of course this one would play the movie again, so you probably want
// to call that later on a button click or something.
currentSWF.gotoAndPlay(1);
}
I am importing several external files using the Loader-class, and one of them is an swf-file. When doing so (I had done it successfully before, so did not expect any issues), I ran into all sorts of errors, and finally Flash crashed.
I put down a trace in the constructor function, and it didn't trace just once, but kept on tracing, suggesting that the constructor was stuck on loop. I guess the loading of too many of the same swf is what causes flash to eventually crash.
Here is my code (the swf im loading is now a simple test-file which contains an image and no code):
private var slides:Loader = new Loader();
public function DocumentClass()
{
trace(1)
slides.load(new URLRequest("Resources/Slides.swf"));
slides.contentLoaderInfo.addEventListener(Event.COMPLETE, SlidesComplete);
}
public function SlidesComplete(evt:Event):void
{
slides.contentLoaderInfo.removeEventListener(Event.COMPLETE, SlidesComplete);
addChild(slides);
}
This traces "11111111111..." and everything dies in the end.
HELP!
Try putting a stop() action at the top of the swf you load in (either in actionscript, or on the timeline). It's possible that the swf is being loaded in and is running a play and running on loop in the mean time (hence your code running over and over).
I would do a progress watch until the swf is fully loaded, then jump to your display frame:
Create a section for loading (your choice if you want to use a preloader)
Create another section (set of keyframes) for loaded content. I use keyframes because it's easy, but you could also wait to instantiate classes until loading is complete.
Below is a snippet I occasional build from:
// stop the playhead from moving ahead
stop(); // you can also use gotoAndStop("loading"); if you want
function loaderProgressHandler(event:Event):void {
// switch the framehead to main which will show your content
if(event.bytesLoaded >= event.bytesTotal) {
event.target.removeEventListener(Event.PROGRESS, this.loaderProgressHandler);
this.gotoAndStop("main");
}
}
this.loaderInfo.addEventListener(Event.PROGRESS, this.loaderProgressHandler);
Hope that helps!
I was just stuck on this same problem.
In my case it turned out that the problem was down to the swf having the same document class name as the swf that was loading it.
eg. Main.as was loading another swf that also had its document class called Main.as - Changing this to anything else solved the infinite loop.
I have an FLA file with two frames. On the first frame I have nothing but a textfield and some code to do the preloading. After it is done preloading it does gotoAndStop(2)
On frame 1 I have:
stop();
stage.scaleMode = StageScaleMode.SHOW_ALL;
//Import the required assets
import flash.display.*;
//Stop the playhead while loading occurs
this.stop();
//Create a listener to call the loading function as the movie loads;
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, PL_LOADING);
this.loaderInfo.addEventListener(Event.COMPLETE, PL_FINISH);
function PL_LOADING(event:ProgressEvent):void
{
var pcent:Number = event.bytesLoaded / event.bytesTotal * 100;
//Display the % loaded in textfield
txt.text = int(pcent) + "%";
//If the movie is fully loaded, kick to the next frame on the main timeline
}
function PL_FINISH(event:Event):void
{
removeChild(txt);
gotoAndStop(2);
}
On frame 2 I have nothing except:
var game:Game = new Game();
addChild(game);
In my publisher settings I have export to frame 2.
My problem is that the preloader won't display until 100%. Does anyone know why?
P.S. For testing I put a large image file on the stage in frame 2 and the result is the same.
This normally happens if you haven't deselected "Export in frame 1" in each of the library symbols that you are exporting for ActionScript.
You'll need to make sure that you create reference to these objects (so that ActionScript can access them) by placing them onto the stage in frame 2 (out of sight).
What's happening is that all of the symbols are being loaded before the preloader itself has loaded.
If this isn't the issue, then please provide some code so I can better assess your issue.
Have you tried putting something static on frame one? Just because there is a preloader, that doesn't mean that your swf will be displaying at all...
I know that I had one swf once which simply took a minute to actually get the Flex preloader to even show up because of network latency. It could be that your swf isn't displaying until 90% of it has already loaded.
I´m dealing with similar problems, and there is something i found out: my antivirus contains a kind of "browser protection" feature, which sort of checks all files in advance before it allows the browser to actually display them. If this antivirus feature has not been installed on the system, the preloader works beautifully. I´ve checked some other web-sites with flash content, and they also behave "wrong" under these circumstances. Now, some people seem to have found a way to stop the antivirus from messing around, but i don´t know how they do it... not yet...