
216
CHAPTER 11
Notice that we are handling both the initialize event and the creationComplete event. The init()
method specified as the event handler for initialize registers all of the Fireworks event handlers
that were previously handled in the DrawRect constructor of the Flash ActionScript 3 project. We can
still use the include statement to read in JSF code. We’ve done this on the first line in the <mx:Script>
section: include "jsf/jsfCode.as". The jsfCode variable defined in the external file is accessible as
a member of this application, which means we can continue to load the external JSF variable using
MMExecute(jsfCode).
Note also that adobe.utils.* is now imported and flash.external.ExternalInterface is not.
Following is the init method, defined in the CDATA section of <mx:Script />:
private function init():void
{
// Register all Fireworks Event Handlers
ExternalInterface.addCallback("IsFwCallbackInstalled", ➥
IsFwCallbackInstalled);
ExternalInterface.addCallback("onFwDocumentOpen",onFwDocumentOpen);
ExternalInterface.addCallback("onFwDocumentClose", ➥
onFwDocumentClose);
ExternalInterface.addCallback("onFwActiveToolChange", ➥
onFwActiveToolChange);
ExternalInterface.addCallback("setfwActiveToolForSWFs", ➥
setfwActiveToolForSWFs);
ExternalInterface.addCallback("onFwActiveSelectionChange", ➥
onFwActiveSelectionChange);
// Handle Resize Event of Panel
this.parent.addEventListener(Event.RESIZE, UpdateLayout);
}
private function UpdateLayout(e:*=null):void
{
this.width = this.parent.width;
this.height = this.parent.height;
}
As in Flash ActionScript 3 projects, ExternalInterface.addCallback is used in Flex to register event
handlers for Fireworks events, like onFwActiveSelectionChange or onFwDocumentOpen. We have
also added an event handler to the Event.RESIZE event of the movie. When this event is fired, the
UpdateLayout method is called, which updates the size of this application to match the size of the
parent window. Without this event handler in place, the Flex layout will not resize in Fireworks as
expected. Figure 11-14 shows the DrawRect Flex project open in Adobe Flex Builder. We have used
the native Flex components to re- create the original Flash panel in Flex. Instead of using a component
like AlignmentManager to handle layout, we now rely on the Flex panels and their support for dynamic
repositioning and scaling at runtime.
Kommentare zu diesen Handbüchern