View Full Version : Swf to Swf communication
kongo
05-16-2009, 10:01 PM
Hey folks
I'm trying to build an app for distribution on DVD which consists of a main menu (swf1 - projector) with a video playlist and separate window with the video player (swf2 - browser).
I'm currently using LocalConnection to tell swf2 which video to load and I'm popping the new window open with URLRequest("videoplayer.html").
But each time you load a new video, a new browser window opens.
Does anyone know of a good way for swf1 to check whether the swf2 window is already open?
northcode
05-19-2009, 08:17 PM
Unless you switch to a commercial ($) swf2exe tool, LocalConnection is really your only choice. You could store some state in a shared object but that's a bit dangerous because if the state isn't cleared before the second app ends your main app will always thing the second app is running. The only other solution would be to use a helper application to launch your second app and have it check to make sure only one copy of the second app was running. It would require writing a small application to do the work though (means you'd need to know C++ or something that can produce standalone applications).
kongo
06-02-2009, 09:53 AM
Thanks northcode,
C++ is out for me and I havent looked into commercial options ie swf2exe software as I want this to run on Macs as well.
I did in fact end up using 2 local connections. LC1 checks whether theres a window open and if so, deploys the movie.
I used a status event to check whether LC1 worked or not.
ActionScript Code:
LC1.addEventListener(StatusEvent.STATUS, onStatus);
function onStatus(event:StatusEvent):void { if (event.level == "error")
{ loadWindow();
} }
In the case of 'error', I run the loadWindow() function which a) opens the browser window then b) waits 10secs for the browser to finish opening (designing this with slow XP machines in mind) then c) sends the value of the flv to be played as a param of LC2.send.
ActionScript Code:
function loadWindow():void { var popURL:URLRequest = new URLRequest("player.swf");
navigateToURL(popURL);
myTimer.start();
myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
function timerHandler():void { var LC2:LocalConnection = new LocalConnection();
LC2.send("con2", "talk2", sendObj);
} }
Now I'm sure there must be much better ways of doing things.
This is my first big project using AS3 and to be honest my code is getting hackier and hackier.
Waiting for 10secs to load is not ideal for fast machines.
I'm trying to figure out how to have a smarter checking system.
Also if you close the player window then try to reloaunch the same video from the menu, you get an echo - the flv seems to load twice. If you keep closing and relaunching, it keeps loading more and more instances of the flv. Fun times...
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.