A question popped up on flexcoders recently about whether these two could play together and here's my response. Yes, it's possible using SWFLoader. The 9 SWF will be accessible/programmable through the content property of the loader. Here's a very basic example:


import flash.events.Event;

private function initSWF(event:Event):void{

public function clickHandler(event:Event):void{
    var button:String = loadedSWF.content["clickedButton"];
    //do something with the returned data


So, the above code can go in a < mx:Script >< /mx:Script > block or in an external ActionScript file that's the source property of your script block, < mx:Script source="external.as" />. First, we import the Event class so we can listen for and dispatch events. Next comes initSWF(). This method is the event handler for the SWFLoader's complete event.

If that was confusing, it's the function that get's called when the complete event fires. So, what we're doing with this method is adding an event listener to the Flash 9 SWF that we load. And, when the loaded SWF fires the "clicked" event we want to handle that with clickHandler(), which right now is just holding a reference to the name of the button clicked. To get the ball rolling, simply make initSWF() the value of the complete property of your SWFLoader component, < mx:SWFLoader  id="loadedSWF" complete="initSWF(event)" source="pathToSWF" />.



import flash.events.*;

var clickedButton:String = "";

someButton.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(event:Event):void{
   clickedButton = event.target.name;
   dispatchEvent(new Event("clicked"));


OK, on the Flash side we do our import first of course. Next, we instantiate our clickedButton variable as an empty string (just to keep from being null/undefined). Now, we add an event listener to the someButton instance on the main timeline. This syntax is a much cleaner way of dealing with events IMO because everybody (you, your team, the compiler) knows exactly what you're trying to do.

Here we want to listen for the CLICK event which is a static member of the MouseEvent Class. When we hear the event clickHandler() once again jumps into action. Inside this click handler we do (2) things. First, we set the value of our clickedButton variable to the instance name of the button that was clicked. Then finally, we want to dispatch our custom "clicked" event which, in turn, kicks things in motion on the Flex side.

Again, this is a simple illustration of some of the things you can do using Flex/Flash together. No LocalConnections just pure AS3 conversations. Enjoy...=)