Flex and Flash Flash Are Two Heads Better
Flex and Flash: Flash Are Two Heads Better Than One?
Speaker Information • • • Windows-based Developer - Since ‘ 85 Senior Cold. Fusion MX Developer - Since ‘ 99 Technical Instructor - Since ‘ 85 Flash Developer - Since ’ 99 Flex Developer – Since ’ 05 theo@teratech. com http: //therush. wordpress. com
Presentation Agenda • • Advantages of Flash and Flex Audience Producing the Same Results (kinda) Everything Old is New Again Using Local. Connection Using External. Interface Other Considerations
Advantages Flash • Longevity • Thousands of Flash related resources • Thousands of community created components and samples • Great authoring tool for designers • Visual drawing environment
Advantages Flex • Improved ASv 3 architecture • Improved components • Developer-centric Eclipse based development environment • Predefined effects and transitions
The Flash Audience Timelines Layers Canvas Designer Stage Movie. Clip
The Flex Audience Actionscript Tags Perspectives Developer Data Services Source View
Working Together
Producing the Same Results (kinda) Version 9 only Version 8 and below
In the “Bad Ol’e Days” … • Used get. Url() and fscommand() to communicate from Flash to Java. Script. • Used set. Variable() to communicate from Java. Script to Flash. • fscommand() used VBScript that could conflict with other VBScript on the page and can only pass one string parameter.
Everything Old is New Again Local. Connection External. Interface • Invoke methods between Flash apps/movies • Pass data between Flash apps/movies
Using Local. Connection Why use Local. Connection? • • Supported by Flash Player version 6 and above Uses a one-way “Channel” to communicate Supports asynchronous communication Pass multiple variables
Using Local. Connection How does it work? Step 1 SENDER: • Create a new Local. Connection object (1) • Use send() method of the localconnection object (2) 1) my. LC: Local. Connection = new Local. Connection(); 2) my. LC. send(swf 1, my. Name, name_txt. text);
Using Local. Connection How does it work? Step 2 RECIEVER: • Create a new Local. Connection object (1) • Prepare to receive commands (2) • Define function that will be called by SENDER (3) 1) my. LC: Local. Connection = new Local. Connection(); 2) my. LC. connect(swf 1); 3) my. LC. my. Name = function(param) { reciever_txt. text = param; }
Using Local. Connection How does it work? set. Clock clock. Stopped Provides direct one-way communication between swfs
Using Local. Connection Can you show us an example? The Resort Tracker 2000 v. 5
Using Exteranal. Interface Why use External. Interface? • • • Supports synchronous communication Easier to implement Uses Java. Script as a “proxy” between Pass multiple variables Supports multiple data types Note: Only supported by Flash Player version 8 above
Using External. Interface How does this work? Step 1 SEND TO JS: • Import External. Interface class • Use call() method of External. Interface object Import flash. external. External. Interface. call(“alert”, “Hello from Flash”);
Using External. Interface How does this work? Step 2 RECIEVE FROM JS: • Import External. Interface class • Use add. Call. Back() method of External. Interface object Import flash. external. External. Interface. add. Call. Back(“tween. Me”, this, tween. Me);
Using External. Interface How does this work? Step 3 SEND TO FLASH: • Get reference to Flash object • Use object reference to call Flash function // for IE use my. Flash = window[“flashmovie”]; // otherwise use my. Flash = document[“flashmovie”]; my. Flash. tween. Me(“Hello from JS”)
Using External. Interface How does this work? set. Clock clock. Stopped
Using External. Interface Got another example? The African Country Guide ver. 5
Other Considerations • Flash 8 Security Model • Frame Rate
Other Considerations Flash 8 Security Model • By default, local SWFs can no longer contact the Internet, perform HTTP communication, or communicate with local HTML files. • SWF and HTML content from non-local URLs may no longer load any content (SWF, HTML, PNG, and so on) from local paths. • Use local. Connection. allow. Domain to permit crossdomain scripting. • Use a crossdomain. xml policy file to permit crossscripting operations.
Other Considerations Flash 8 Security Model (cont. ) • Use allow. Script. Access to handle communication with Javascript. • allow. Script. Access – Never: outbound scripting fails – Always: outbound scripting succeeds (default) – same. Domain: outbound scripting allowed only if swf resides in same domain (default in FP 8+)
Other Considerations Frame Rate • • • Flex’s default frame rate is 24 Adjust your Flash movie accordingly You can reset the default Flex frame rate 1. Open Project Properties >> Flex Compiler 2. Add the following into "Additional compiler arguments: " in single line: -default-frame-rate int Note: The maximum frame rate is limited to machine performance, if this value is set too high the player will simply run at the fastest rate that it can on the given machine.
Additional Resources • http: //www. adobe. com/cfusion/knowledgebase /index. cfm? id=tn_16243 • http: //livedocs. macromedia. com/flex/2/langref/ flash/net/Local. Connection. html • http: //www. adobe. com/devnet/flash/articles/ex ternal_interface_05. html • http: //livedocs. macromedia. com/flex/2/langref/ flash/external/External. Interface. html • http: //therush. wordpress. com
Additional Resources Flash / Java. Script Integration Kit (Beta) http: //weblogs. macromedia. com/flashjavascript/ Flex-Ajax Bridge http: //labs. adobe. com/wiki/index. php/Flex_Fram ework: FABridge
- Slides: 28