1

I am trying to run a JSFL script from within a C# project, where the JSFL script opens up a .fla file, modifies it n times, and exports n .swf files before closing. From the C# project, I am starting up the JSFL script through the Process class. I try to wait for the JSFL process to finish through the myProcess.WaitForExit() command, but it doesn't work. The remainder of my code C# executes before the JSFL process finishes exporting its .swf files. Is there any way I can throw something that the C# project can catch from the JSFL file or some other solution?

CodedMonkey
  • 458
  • 1
  • 7
  • 17

5 Answers5

2

Have you tried to set a custom Listener that will execute a function when the JSFL done. Don't forget that it's still based on ECMA which is a procedual language. By the way, JSFL has a LOW-LEVEL C API. C LEVEL API

2

One solution (although most likely not the best one) would be for your C# code to look for the SWF files being created. Only once they've been updated/created will the JSFL script have finished, so you know that it will be safe for your C# to move on. In case there is no way of knowing how many SWF files the C# program needs to look for, you could instead let the JSFL script write to a log file of some sort, and to have the C# program read that log on a interval, looking for some sort of token to indicate that the JSFL script has completed it's task.

Granted, this may be far from the best method (and I don't know C# well enough to know whether what you're seeing is by design or a sign of something being wrong). But it may just be the case that running JSFL/Flash is completely asynchronous and if so, maybe the log file approach is the quickest path to solving the problem.

richardolsson
  • 4,041
  • 1
  • 17
  • 19
  • So I figured it out that the reason this happens is because the JSFL file executes instantly in the command prompt while the actual events in the JSFL file take some time to finish (like exporting multiple .swfs). Question now is, can the JSFL file wait to execute all it's commands before it signals back to the command prompt that it's done? – CodedMonkey Sep 06 '11 at 22:33
  • "Executing a JSFL file" is actually "starting the flash.exe process and passing it a JSLF filename as a parameter." That's what completes immediately. The Flash process will then processes the JSLF file and remain open indefinitely, so waiting on the process will just lock your app until you manually close Flash. The only way an external app can known when Flash has finished an internal operation like processing a JSFL file is to call "runCommandLine" at end of the JSLF script to send a signal to your main application indicating the end of the script has been reached. See my posted answer. – Triynko Jul 24 '14 at 20:32
2

I have the same problem with another application that calls an external JSFL script.

What I do is write a file once finished to a target directory, and in the calling application, poll for that file. As soon as the file appears, I know the task has finished, and I delete the temp file, and carry on. Oh - and before starting I look for and delete any temp files so I don't get a false positive.

It's not so nice as events, but you have to work with what you've got.

Dave Stewart
  • 2,324
  • 2
  • 22
  • 24
0

This is absolutely possible, and I've already posted a solution here on stack overflow, complete with a detailed problem description and all the C# and JSFL source code necessary to implement it: Automating publishing of FLA files; calling Process.Start multiple times

To summarize... first of all, waiting on the JSFL script process is useless, because you're actually calling Flash.exe, which will remain open/running after the JSFL completes, so you'd be waiting on a process exit event that will never occur.

The trick is to use a JSFL function at the end of the JSFL script which executes a windows command line command, and it's that call which will signal your C# app that the JSLF script has completed. So basically you'll have your main instance of your C# app, but you want to modify your C# app so that a 2nd instance can be run from a command line with a particular switch. When you're C# app is called with a particular switch (from the JSLF file), then instead of running normally, you want your program to simply signal a wait handle in the main instance of your application and then close. I use a simple third-party open-source library called XDMessaging, which facilitates such inter-process communication. It lets you open a named channel in your C# app, which can receive a command from the 2nd instance, signaling the main instance that the JSFL script has finished and it's safe to continue.

Community
  • 1
  • 1
Triynko
  • 18,766
  • 21
  • 107
  • 173
-2

But involving file watcher like this is not the best solution so I catch the Flash process and keep watch on the process title and tell the JSFL render some window title for the flash window after finish the execution.