Forum Moderators: open
I have a movie made with (heavily) using AS3, connected to Red5, and also reads data from XML files. When the movie is loaded, it reads an XML file from the webserver, then connects to the Red5, opens and plays a stream, and in the meantime initiates a SharedObject as well. Basically everything works pretty fine (was a long way), but one annoying thing remains:
After the movie is loaded in the player, for about a few seconds (~5 seconds) I'm not able to click anything in the movie, even the mouse pointer is left unchanged when I hover a button, just as if the player would not care about my mouse. After those few seconds has passed, everything runs just fine.
During this time nothing happens anymore, the script runs fine, it does all the job it has to do, even the stream starts to play in 1-2 seconds after loading, but I have to wait ~3 more seconds to have the player react to the mouse events...
Any idea what could block the flash to react to mouse events? As far as I know there's no memory/CPU intensive tasks running in the background, no dead-loops, no tweens, nothing what would make me suspicious. I'm lost...
Thanks for any idea/suggestion!
My apologies if this is a frequently asked question, but looking it on google reveals millions of web pages (for example "flash buttons not working", but I couldn't come up with better phrasing for this, so I gave up on this...)
But actually the answer is yes, because the XML loaded contains the translations of the texts, and I do not show (more precisely it is not visible) anything before this XML is fetched and loaded.
Stripping out few hundred lines, the code looks like this:
public class Client extends Sprite {
//
// Constructor
public function Client() {
// Hide interface
this.showOverlay();
// Start configuring the client
this.loadTexts();
}
//
// Load translations from XML
private function loadTexts():void {
var request:URLRequest = new URLRequest("http://www.example.com/flash_text.php");
this.mui.addEventListener(Event.COMPLETE, Delegate.create(this, function(){
// Initialize the client
this.startClient();
}));
this.mui.load(request);
}
//
// Method for configuring the User Interface
private function startClient():void {
// Initiate network connection
this.connectNetwork();
// There goes dozens of lines containing event listener assignments,
// other UI changes, and so on... This is the place where
// the mouse event listeners are assigned as well.
// ...
// Show interface
this.hideOverlay();
}
//
// Initiates network connection
private function connectNetwork():void {
this.connection = new NetConnection();
this.connection.client = this;
this.connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
this.connection.connect(this.URL);
}
//
// Network status handler
private function netStatusHandler(event:NetStatusEvent):void {
switch (event.info.code) {
case "NetConnection.Connect.Failed" :
// Do something
break;
case "NetConnection.Connect.Success" :
// Continue the configuration...
this.setupSO();
break;
case "NetStream.Play.Start" :
// Playback has started, execution goes idle, stream is being played,
// usually this happens in the fist 2-3 seconds after loading.
// After this point everything is loaded and ready to work - but it isn't...
break;
}
}
//
// Configures shared object
private function setupSO():void {
this.remoteSO = SharedObject.getRemote('remoteSO', this.connection.uri, false);
this.remoteSO.addEventListener(SyncEvent.SYNC, soSync);
this.remoteSO.client = this;
this.remoteSO.connect(this.connection);
}
//
// Sync handler for the remote shared object
private function soSync(e:SyncEvent):void {
if (!this.soSynched) {
// Connect to the Red5 stream
this.connectStream();
// Remember that the SO was synced, so next time called, this piece of code does not run.
this.soSynched = true;
} else {
// Handle changes in SO
}
}
//
// Connects to the Red5 stream
private function connectStream(force:Boolean=false):void {
this.stream = new NetStream(this.connection);
this.stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
this.stream.play('liveStream', -1);
this.monitor.attachNetStream(this.stream);
}
}
For a simpler overiew of what happening here's the order of methods they are called:
Constructor => loadTexts() -> Anonymous method => startClient() => connectNetwork() -> netStatusHandler() => setupSO() -> soSync() => connectStream() -> netStatusHandler()
The mouse event listeners are assigner pretty early, I see no reason why flash does not respond to them? All other event listeners are working fine. If the swf would not be loaded properly (as there's no loader for the flash), it would not work at all, no? Me lost.