0

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?

nabster023
  • 45
  • 5
  • https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/NativeWindow.html – Organis Dec 11 '17 at 13:54
  • So this is an AIR application for desktop? It needs to be. Use the `NativeProcess` feature to load `cmd.exe` with parameters `start C:\someFolder\external.swf`.. Try [**this code here**](https://stackoverflow.com/questions/47700996/as3-get-java-home-path/47745703#47745703) as a quick test. Just replace `NProcess_Args[0] = ("\/c" + "set");` with this command `NProcess_Args[0] = ("\/c" + "start C:\someFolder\external.swf");` – VC.One Dec 11 '17 at 14:19
  • @VC.One I don't think it's appropriate as you have no idea what kind of application is associated with SWF file there (could be none at all, or browser, or media player) and you don't even know if Standalone Flash Projector is installed. I believe that opening another AIR window and loading the external SWF via **Loader** will be the best solution. – Organis Dec 11 '17 at 14:38
  • @Organis if asker does not have standalone player then how do they even know it's possible to _"open it in a new window without using the browser"_? (ie: they have seen the Standalone window before, they simply cannot confuse it with VLC or some browser window). Also the installed `FlashPlayerDebugger.exe` achieves same thing as the Standalone version... PS: Either way sounds good and should be tested by asker for learning experience and options weighting. – VC.One Dec 11 '17 at 15:20
  • Thank you both for your help, @Organis i used the NativeWindow class and successfuly opened a new window but how can i load an SWF file inside that window? because i don't have access to it. – nabster023 Dec 12 '17 at 10:07
  • @user3010564 Added an answer. It is pretty much self-explanatory. – Organis Dec 12 '17 at 19:35
  • @user3010564 If the provided answer is working then accept as correct Answer by ticking the `✔` icon. Thanks. – VC.One Dec 13 '17 at 04:46

1 Answers1

1

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:
// https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/NativeWindow.html#NativeWindow()
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);

newWindow.activate();

// 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:
newWindow.stage.addChild(aLoader);
Organis
  • 7,243
  • 2
  • 12
  • 14
  • 1
    Thanks, it helped a lot. One more thing, when i load the SWF file in the new window, it doesn't use the full space available, image:[link](https://img15.hostingpics.net/pics/524470zer.png) the SWF file content appears on top left i tried using: stage.displayState = StageDisplayState.FULL_SCREEN; but no results any ideas? – nabster023 Dec 13 '17 at 11:24
  • @user3010564 Did you try set the new window bounds to actual SWF width and height? – Organis Dec 13 '17 at 18:31
  • Yes, the SWF file i want to load in the new window has a size of 1280x800. This the what i did: newWindow.bounds = new Rectangle(100, 100, 1280, 800);. when the new window opens, it has a size of 1280x800 and SWF file fits perfectly, but when i maximize the window i get the result that i shared in the image above. – nabster023 Dec 14 '17 at 10:01
  • @user3010564 Play with **scaleMode** of the window's **stage**. Probaly you need to set it to **StageScaleMode.SHOW_ALL**. – Organis Dec 14 '17 at 19:34