Flex 2 and Flash 9 Together?

The Answer...
Hasan Otuome
Hasan Otuome is Chief Architect for Marx Media (http://www.marxmedia.net) where he can usually be found developing Rich Internet Applications for the company's clients. He champions creative uses and combinations of Flash, PHP, AJAX and MySQL, among others, for their benefits in user experience improvement.
View all articles by Hasan OtuomeFlex
========
import flash.events.Event;
private function initSWF(event:Event):void{
loadedSWF.content.addEventListener("clicked",clickHandler);
}
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" />.
Flash
========
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...=)
Spread The Word
Related Articles
- Loading Images Via XML into Flash MX 2004
- Firefox Plugins for Flash Platform Developers
- Flash E-learning Presentations for LMS with authorPOINT 3.7
- Intro to E4X
- FlashJAX v1.0 Released
- Communication between two movies
- Flash MX Object Oriented Menu using PHP
- Flasherize release ChatRoom
- The PrintJob class
- Controlling Multi-channel Sound using ActionScript
- FlashSQL Version 2 released
- Class For Genrating Random Number
- Intervals in Flash with setInterval
- Flash Alpha Innacuracies
- FlashRelief announces QuickPoll
- DoubleClick event for movie clips and buttons
- Creating a Visitors Counter for your flash site
- Detecting Key Combinations
- Blue Pacific Software Releases Turbine Video Encoder Version 2.0
- Easy autoFocus
- Business is booming at Beatsuite.com following BBC film
- amfphp 1.0 released
- Componentsforflash.net announces News Feed & Blogger Component
- FlashJester Announces Jugglor 2.2. and Flash Handout
- Easy Movieclip Scrolling in Flash 8
- Blue Pacific Software Releases Turbine Video Engine SDK Version 2.0
- FIRST SPARK CONFERENCE DRAWS 750 ATTENDEES FROM 27 COUNTRIES
- FlashRelief announces ThumbGallery
- Flashforward Conference and Film Festival Announces First 2006 Event
- Actionscript for Flash 5 dummies: Creating radio buttons
- CSS in Actionscript 1.0
- Abstract Class in AS2.0
- Loading random Background and/or Screensaver
- Adding MM Components Dynamically
- Affine transformation matrix and beginGradientFill
- Advanced Actionscript 2 Computer Graphics Particle Systems and Object Oriented Class Design
- Flash MX 2004 Undocumented Tween/Easing Classes Documented
- Dynamic masking using the drawing API II
- Dynamic masking using the drawing API
- Flash MX Audio Player
- A Maze Engine for Flash Games, Using ActionScript 2.0
- Color fade
- Learn how to access and run php procedural functions from within Flash MX
- Advanced Flash MX Sound Timing
- Creating Flash MX Custom Component Help
- class and object in games
- 3D Face Extrusion
- Dynamic text with scrollbar
- Building a Tsunami
- Detecting the Mouse Angle
- Advanced Slider Menu
- Circle Collisions
- Advanced Double Click
- Constrain to Arc with Algebraic Formula
- Active Search List
- Introduction to Flash and PHP
- Dynamic menu with a tracking mc
- A Scalable Scrolling Newsreel
- 'Cool and Practical' Sound Effects
- Fast Forward and Rewind for a Jukebox for MX 2004
- Flash Physics Study
- Flash Broadcasters and Listeners
- Simple Particle Effect
- Flash MX Skip Intro
- ASSetPropFlags
- ASBroadcaster
- Dynamically Attaching Components
- Advanced Pathing
- Loading, Editting and Saving Variables via Perl And Flash ActionScript
- E-Cards and other Dynamic Systems
- Delaying Actions
- Invoking Actions From HTML Textfields
- Full Screen Popup Windows
- Changing a HTML page's background color via Flash
- FS Command JavaScript Library
- loadVariables Interaction between Flash backend scripts
- Draw a line
- Collision Detection
- Game with laser
- Actionscript Powered Movement
- Continuously Scrolling Text Field / Graphic Objects
- Arrays in ActionScript
- Creating preoloaders for the attachSound Method
- Creating the Time with Flash 5
- Dynamic counter (PHP3+Flash 5)
- Animating Text By Using ActionScript
- Local Connection
- How to Use the Easy Slideshow Component v1.0
- Counteracting Flash's Automatic Resize
- Creating a basic animation
- 3D Input Text effect
- Basic Scrolling
- Common Errors and Debugging
- Building a Binary Clock
- Creating a continuously scrolling newsreel
- Creating custom mouse pointer
- Loading External XML formatted Content into Flash MX 2004
- CSS in Flash MX 2004
- Integrating Flash and mySQL
- Building games in flash
- Flash Projectors and Crossplatform (Hybrid) CD burning
- Creating Flash 5 Quizzes
- Displaying the Date and Time With Flash MX
- LoadVariables and LoadVars Objects
- Basic Animation Via ActionScript
- Converting Basic HTML Forms to Flash
- Blur transition effect
- Controlling Different Timelines
- Initializing Movie
- Navigation Circle That Stops On Mouse Over
- Execute Files from Local Presentations
- Actions using External Scripts
- DOS Cursor Text Effect
- Launch Applications using Flash
- Detect flash plugin using flash
- Drag 'n Drop and Drop Targets
- Bookmark to IE
- Drop down menu
- Continuously Looping Background
- Get Property
- Instance Names
- Context Menus in Flash MX 2004
- Jigsaw Puzzle
- Flash MX (PHP) Remoting
- Creating a Dynamic Drawing application in Flash
- Dynamic menu with submenus
- Easing Menu System
- Drag and Drop Disk Menu System
- Banning Words In Flash Forms
- Dynamic Layout Control
- FLASHLOADED RELEASES ZOOMMENU
- Launch of Amara Flash Photo Animation Software For immediate release July 13, 2005
- Flashrelief announces new Flash component for creating HTML style tables in Flash.
- ELECTRIC RAIN RELEASES SWIFT 3D 4.5 FOR 3 D EXPORT TO FLASH AND VIDEO
- Apress.com Opens for Business
- Digitalanand Release Motion Effect Video Loops
- BJC Components released at Flashloaded
- Blue Pacific Software Releases Rich Chart Server
- InfoSoft Global has recently released FusionCharts Lite 1.0, a FREE Flash charting component
- ELECTRIC RAIN LAUNCHES SWIFT 3D MAX AND SWIFT 3D LW 3.0 ADDING NEW FLASH RENDERING CAPABILITIES TO DISCREET 3ds max, AUTODESK Viz AND NEWTEK LIGHTWAVE 3D
- Eovia Ships VectorStyle 2
- FlashTextEditor released at Flashloaded
- GhostWire Components Set 7 Released
- Akamai and Macromedia Announce Availability of Flash Video On-Demand Solution
- Flashloaded introduces Flash Video Loops
- imageLoader released at Flashloaded
- Macromedia and Mirror Image Partner to Deliver Flash Video Streaming Services
- flashTimer released at Flashloaded
- Macromedia Captivate Now Available
- Flashloaded Releases xmlCalendar Component
- ELECTRIC RAIN SWIFT 3D 4.0 AND SWIFT 3D XPRESS NOW AVAILABLE FOR MAC OS X
- AS2DOC PROFESSIONAL - DOCUMENTATION GENERATOR FOR ACTIONSCRIPT 2.0 AVAILABLE
- ELECTRIC RAIN ANNOUNCES MAC OS X VERSION OF SWIFT 3D XPRESS - 3D PLUG-IN FOR MACROMEDIA FLASH MX 2004
- Flashtival 2004, the largest webdesign conference in the Benelux
- Macromedia Delivers Update of Macromedia Flash MX 2004
- European Flash Conference Barcelona 2004
- Macromedia Announces FlashPaper 2
- Macromedia Announces Web Publishing System
- Macromedia Announces Contribute 3
- 16 Flash(tm) Film Festival Winners Announced
- Macromedia delivers Flash Lite 1.1
- GhostWire Components Set 6 released
- Macromedia Breeze Expands its Global Reach
- Flashloaded releases bannerRotator and iconbarMenu
- GhostWire Components - Flash MX 2004 now supported
- Flash(tm) Film Festival Nominations Close May 7
- Flash Remoting Server for .Net - final Beta release
- Finally, A Flash conference in the Midwest.
- AS2DOC DOCUMENTATION GENERATOR FOR ACTIONSCRIPT 2.0 ANNOUNCED
- Create Custom Multimedia Apps and Players with New Slick TV Studio
- Flash Designer Simplifies the Process of Creating Flash Animations
- DoubleClick and Macromedia answer the call of advertisers in need of simplified rich media technology
- GhostWire Components Set 5
- Macromedia announces RoboHelp X5
- Macromedia announces RoboInfo 5.0
- Macromedia Director MX 2004 now available
- Jugglor v2.0 Arrives from FlashJester
- Flashloaded launches Sound Player and RSS Reader
- lynda.com Announces "Learning ActionScript 2.0 in Macromedia Flash MX 2004"
- Macromedia announces Macromedia Director MX 2004
- Macromedia Breeze Live now available
- BJC Multiple Document Interface Component (MDI) (12K)
- Macromedia Central Developer Release now available
- Beam Jive Consulting CCS1 (Control Component Set 1) components
- IMPERATOR °FLA now available
- flashLight Designer and flashLight Developer now available
- GhostWire Studios release GhostWire Components Set 4
- Create Adventure Games in Flash Using FACE
- EGO7 rolls out solutions for Site Management and Application Delivery
- Flashloaded releases two news tickers : flashTicker & flashTickerFX
- FlashMX 2004 ActionScript 2.0 wordfile for Ultraedit
- Macromedia announces New Teaching Curriculum and Resources
- FLASHANTS releases SWF2Video Plug-in for Adobe Premiere Pro
- Avery Dennison builds innovative digital photo ID solution using Macromedia technologies
- Dynamic Flash generating server tool
- GhostWire Components Set 1 released
- Macromedia announces Next Generation of MX
- FLASHANTS launch new iceProjector V1.5
- InfoSoft announces FusionCharts 2.0
- Macromedia ColdFusion MX 6.1 now available
- Macromedia Contribute 2 now available
- Doubleclick and Macromedia launch new rich media product, DART Motif
- Fonts For Flash releases Super Pixel Fonts
- Macromedia ColdFusion MX now "Java Verified" for portability across J2EE application servers
- Access licenses Macromedia Flash SDK to deliver embedded browser for appliances
- Interactive Flash MX Training Wins Industry Awards
- Launch of Flashation Web Menu Builder
- Macromedia DevNet resource kit volume 3 now available to DevNet subscribers
- Macromedia announces Macromedia Flash MX data connection kit
- ActionScript.org Components Competition Winners Announced
- 19.5 Degrees launched De Flash, on behalf of SavagePro.
- MACROMEDIA DEVNET SUBSCRIPTIONS
- Asset Mover 1.1 Update. OS X Version Released.
- ELECTRIC RAIN ANNOUNCES DEVELOPMENT OF SWIFT 3D 3.O FOR MAC OS X
- Components Competition Begins
- Macromedia delivers FreeHand MX
- FlexiDev Release Asset Mover - No more Linkage and Preloader Hassles!
- friends of ED and Electric Rain Inc. are pleased to announce the publication of Foundation Swift 3D - the ultimate guide to out of the box 3D design.
- Macromedia ColdFusion MX updated to support Sun One Platform
- Macromedia ColdFusion MX updated to support IBM Websphere Application Server 5
- Macromedia ColdFusion MX for BEA WebLogic now available
- Macromedia Director MX now available
- ELECTRIC RAIN LAUNCHES SWIFT 3D MAX 2.0 ADDING NEW FLASH RENDERING CAPABILITIES TO DISCREET 3ds max and AUTODESK Viz
- Macromedia Contribute now available
- Macromedia Director MX Contains Unprecedented Accessibility Support
- Macromedia delivers Macromedia eLearning Centre through partnership with Skillsoft
- Doubleclick and Macromedia form Strategic Alliance to Develop Rich Media Solutions to Improve Effectiveness of Online Advertising
- Christmas begins early with Macromedia!
- Flashants and Wildform Release a Joint Solution for Video Titling
- Electric Rain Launches Swift 3d 3.O For 3d Export To Macromedia® Flash™
- EOVIAT Launches VectorStyleT
- Macromedia ColdFusion MX For Sun One Now Available
- Macromedia ColdFusion MX For IBM Websphere Application Server Now Available
- Macromedia ColdFusion MX For J2EE Application Servers Now Available
- FLASHANTS releases SWF2Video plug-in for Adobe Premiere
- Australian Effects And Animation Festival
- ActionScript.org Open Source Competition Winners Announced
- Macromedia announces expanded Macromedia Flash Player Distribution Agreement with America Online
- Macromedia brings Macromedia Flash Support to HP iPAQ Pocket PC
- Macromedia Delivers Macromedia Flash Communication Server MX
- FLASHANTS Launches iceProjector 1.0
- Flashforward2002 and the Flash(tm) Film Festival, New York City Announced
- ActionScript.org Launch the Friends of Ed ActionScript Competition
- Macromedia Delivers New MX Product Family for Creating Rich Internet Applications
- Macromedia Dreamweaver MX Includes Unprecedented Accessibility Support
- Macromedia Announce JRUN 4
- Macromedia Announce Fireworks MX
- Macromedia Announce Flash MX (Various Releases)
- Fly-In Drop-Down Menus
- Dynamic Sound Fade
2 Responses to "Flex 2 and Flash 9 Together?" 
|
said this on 18 Feb 2007 10:11:46 PM CST
I found a good example of
|
|
said this on 20 Nov 2007 10:33:03 AM CST
The line
dispatchEvent& must be dispatchEvent&# Thanks... |


Author/Admin)