Jump to content


Photo

Building Fireworks panels in Flex 3?


  • Please log in to reply
8 replies to this topic

#1 jdunning

jdunning

    Fireworks Ninja

  • Members
  • PipPipPipPipPip
  • 173 posts

Posted 01 September 2009 - 07:00 PM

I'm wondering if anyone has a working example of a Fireworks panel built in Flex 3 where the panel listens for the special FW events, like onFwActiveSelectionChange. I've seen sample code for Flash AS3, but nothing for Flex, and what I've got so far isn't working. The events never seem to get fired, even though I'm returning true from the IsFwCallbackInstalled() handler. Any pointers to working Flex code would be appreciated.

Thanks.

#2 jdunning

jdunning

    Fireworks Ninja

  • Members
  • PipPipPipPipPip
  • 173 posts

Posted 11 September 2009 - 05:35 PM

I'm wondering if anyone has a working example of a Fireworks panel built in Flex 3 where the panel listens for the special FW events, like onFwActiveSelectionChange.

Okay, I got this working. The trick was to register the events earlier in the start sequence of the app. I was waiting until the applicationComplete event fired, which was apparently too late. I switched to doing it on the preinitialize event, and now it works. For the curious, here's the code:

private function onPreinitialize() : void
{
		// we need to register these callbacks early in the startup process.
		// registering them from applicationComplete is too late. 
	if (ExternalInterface.available) {
		ExternalInterface.addCallback("IsFwCallbackInstalled",
			onIsFwCallbackInstalled);

			// create a handler for all the supported events
		for (var eventName in SupportedFWEvents) {
			ExternalInterface.addCallback(eventName,
				createFWEventHandler(eventName));
		}
	}
}

SupportedFWEvents is an object whose properties are the names of the events I want to handle, so looping through the property names lets me create a handler for each event. Adding or removing a handler is as simple as modifying the SupportedFWEvents object.

The problem now is dealing with active tool changes. Trevor describes it well in this tutorial: http://www.adobe.com...els_pt2_08.html

When the user's editing text, FW constantly fires events, which creates a fair amount of overhead. I want to ignore events while the text tool is selected. That requires knowing which tool is selected, but the onFwActiveToolChange event doesn't give you the tool name. So you have to call over to the JS side to get fw.activeTool. But doing that interferes with the UI in FW. For instance, I can't change to the scale tool if I check fw.activeTool immediately on getting the onFwActiveToolChange event. Clicking the button or pressing the hot key just doesn't work.

Trevor said there's a workaround:

Thankfully there is a workaround for this issue. When Fireworks recognizes an onFwActiveToolChange event handler defined for a SWF panel, it sets a variable in the main Timeline called onFwActiveToolChange, which Fireworks updates automatically as tools in Fireworks change:

var onFwActiveToolChange;
onFwActiveToolChange = function(){}

No JavaScript code is required in onFwActiveToolChange to make this work because it's all handled internally. The automatic fwActiveToolForSWFs variable provides the current tool's name as a string for you. Those relating to the text and transform tools in the English version of Fireworks include: "Text", "Scale", "Skew", and "Distort".


Of course, this was written back in the days of AS1, I think, I'm not sure how to access this variable in Flex 3, or if it's even possible. I've tried MovieClip(stage.root).fwActiveToolForSWFs and stage.root["fwActiveToolForSWFs"], and neither work. Also tried without the stage. part.

Is the fwActiveToolForSWFs variable supported in AS3? You still out there, senocular?

#3 jdunning

jdunning

    Fireworks Ninja

  • Members
  • PipPipPipPipPip
  • 173 posts

Posted 12 September 2009 - 02:45 PM

I'm not sure how to access this variable in Flex 3, or if it's even possible. I've tried MovieClip(stage.root).fwActiveToolForSWFs and stage.root["fwActiveToolForSWFs"], and neither work. Also tried without the stage. part.

Guess I'll just keep replying to myself, for posterity's sake. :) Thanks to some clues in the free chapter from Grant Hinkson's "Foundation Fireworks CS4" book, I was able to figure out how to get the FW events working in Flex 3. The key was the otherwise totally undocumented setfwActiveToolForSWFs event, which seems to be the AS3 replacement for the fwActiveToolForSWFs variable in AS2. What isn't shown in Grant's example code is that the setfwActiveToolForSWFs handler is unlike all the other FW event handlers in that it gets called with a parameter: the current tool name. With this information, you don't need to call MMExecute to get the current tool name through the FW API.

The code looks something like:

ExternalInterface.addCallback("setfwActiveToolForSWFs",
    function(toolName) { MMExecute('alert("' + toolName + '")'); }
)
That should show an alert whenever the tool changes.

Anyway, thanks to Grant's book, I'm one step closer to releasing a library for building FW panels using only JavaScript...

#4 rzero

rzero

    Fireworks Sparkle

  • Members
  • Pip
  • 3 posts

Posted 09 March 2010 - 03:44 PM

I think this is the only post on the web about this question... so you're my last hope....
I just spent so much hours trying to make this work... without result. I've tried so hard... two more hours and I think I will throw this computer by the window... so my question is : how the hell did you made this working ? I mean, I've done all like you said : preinitialize event » ExternalInterface.addCallback( 'isFwCallbackInstalled', onFwCallback ), for a first test , I just wanted trace the list of event that FW try to "scan" in the SWF. But my flex panel just can't hear the initial "isFwCallbackInstalled", like all my flash panel receive when FW open them...
Only when i reduce and then expand my panel in fireworks, it shows me that fireworks try to send a "onFwMovieStop" event, sometimes a "onFwActiveToolChange"... that's all. :'( !!!
Can you please show or send me a little exemple of a working flex swf.
Please!!! you really can help to save a computer... and more than a computer... a man's brain, a poor man's mental health...
please

#5 jdunning

jdunning

    Fireworks Ninja

  • Members
  • PipPipPipPipPip
  • 173 posts

Posted 09 March 2010 - 09:23 PM

I think this is the only post on the web about this question...

I would not be surprised. :|

I've done all like you said : preinitialize event ExternalInterface.addCallback( 'isFwCallbackInstalled', onFwCallback )

I believe that should start with a capital "I": IsFwCallbackInstalled Are you returning true from that function for the event names you want to handle?

The other thing that's apparently crucial is to use build 477 of Flex 3. The later versions of the compiler (at least up through 3.3) seem to have broken the FW event support. I got build 477 from here: http://opensource.ad...0.477&pkgtype=1

If I load a panel built in 477, then I can load panels built in later versions of Flex, and they all work. But after restarting FW, the panels built in later versions stop working. There's something magic about 477.

Hope that helps save your mental health!

#6 rzero

rzero

    Fireworks Sparkle

  • Members
  • Pip
  • 3 posts

Posted 10 March 2010 - 02:02 AM

thank you so much !!! :)
i'll try to find this magic version number tonight

#7 rzero

rzero

    Fireworks Sparkle

  • Members
  • Pip
  • 3 posts

Posted 11 March 2010 - 02:03 AM

i can't understand why, but you're absolutly right. It perfectly works with this build.
I've tried to look into generated actionscript, but no fundamental changes...
I wonder how you found this one... but life will be to boring without mystery :)
So thank you again for saving my mental health.
A bottle of Champagne is waiting for you in France !!!

#8 jdunning

jdunning

    Fireworks Ninja

  • Members
  • PipPipPipPipPip
  • 173 posts

Posted 12 March 2010 - 04:41 PM

I wonder how you found this one... but life will be to boring without mystery :)

One of the FW engineers pointed me in the right direction. Something broke after that first Flex 3 release, but I can't believe they haven't fixed it yet.

A bottle of Champagne is waiting for you in France !!!

Be right there!

#9 jdunning

jdunning

    Fireworks Ninja

  • Members
  • PipPipPipPipPip
  • 173 posts

Posted 11 May 2010 - 10:32 AM

Another tricky thing about setfwActiveToolForSWFs is that you won't receive it unless you also tell FW that you want the onFwActiveToolChange and onFwActiveToolParamsChange events (not sure if they're both actually necessary, but at least one seems to be). You do this by returning true from the IsFwCallbackInstalled() call for those event names.

Also note that the results of IsFwCallbackInstalled seem to be cached for a given SWF during the session. So if you return true once for an event, you can subsequently return false yet you'll still receive the event. This can be really confusing as you may make a change, the SWF will continue to work, and then the next time you run FW it doesn't.