user3010564 user3010564 - 7 months ago 55
ActionScript Question

Opening an SWF file in a new window

I have a button in my desktop flash application, when clicked, it must load an external SWF file and open it in a new window without using the browser.
i've tried

import flash.system.fscommand;

loadButton.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
fscommand ("exec", "external.swf");

But it didn't work. Someone mentioned in a forum that the app must be compiled as a .EXE file for this code to work. is that true?.

i've also tried

loadButton.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
navigateToURL(new URLRequest("external.swf"), "_blank");

But this opens the file in a new browser window.
Any idea how can i do it without using the browser window?

Answer Source

It is simple with the NativeWindow. Despite the fact the NativeWindow is a separate window, your application is still a whole and have a full access to everything, the new window included. You just need to add a Loader with another SWF to the new window's stage.

// This is an example from official docs:
var windowOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
windowOptions.systemChrome = NativeWindowSystemChrome.STANDARD;
windowOptions.type = NativeWindowType.NORMAL;

var newWindow:NativeWindow = new NativeWindow(windowOptions);
newWindow.stage.scaleMode = StageScaleMode.NO_SCALE;
newWindow.stage.align = StageAlign.TOP_LEFT;
newWindow.bounds = new Rectangle(100, 100, 800, 800);


// Now the only thing left is to load the external SWF into it:
var aLoader:Loader = new Loader;

// Load SWF as usual:
aLoader.load(new URLRequest("external.swf"));

// Add it as a child to the new window's stage:
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download