Académique Documents
Professionnel Documents
Culture Documents
1 2
2006 Adobe Systems Incorporated. All Rights Reserved. 2006 Adobe Systems Incorporated. All Rights Reserved.
3 4
2006 Adobe Systems Incorporated. All Rights Reserved. 2006 Adobe Systems Incorporated. All Rights Reserved.
5 6
2006 Adobe Systems Incorporated. All Rights Reserved. 2006 Adobe Systems Incorporated. All Rights Reserved.
1
FSCommand and SetVariable (“the hard way”) FSCommand and SetVariable (“the hard way”)
To call the JavaScript function xxx_DoFScommand(…) use fscommand() within SetVariable() provides a primitive means of communication with the Flash
the ActionScript. Player using JavaScript.
7 8
2006 Adobe Systems Incorporated. All Rights Reserved. 2006 Adobe Systems Incorporated. All Rights Reserved.
FSCommand and SetVariable (“the hard way”) ExternalInterface (“the right way”)
SetVariable will call a setter function on the root of the current swf ExternalInterface provides a programming interface that allows straight forward
two-way communication between ActionScript and the Flash Player host
environment.
Step 4: Setup AS code to handle SetVariable calls
package Step 1: Setup AS code that will be invoked from JavaScript
{
import flash.display.Sprite; package
{
… import flash.display.Sprite;
public class FSCommandExample extends Sprite
{ public class ExternalInterfaceExample extends Sprite
… {
public function set circleDia(value:int):void …
{ public function drawCircle(dia:int, x:int, y:int, color:int):void
{
_circleDia = value; var circle:Shape = new Shape();
} child.graphics.beginFill(color);
… child.graphics.drawCircle(dia, dia, dia);
} child.graphics.endFill();
} addChild(circle);
}
…
9 10
2006 Adobe Systems Incorporated. All Rights Reserved. 2006 Adobe Systems Incorporated. All Rights Reserved.
ActionScript can call JavaScript directly and synchronously. ExternalInterface is available on the following platforms:
Get return values, pass any data type arguments, including strongly typed objects
Browser Operating System
Internet Explorer 5.0 and later Windows
Netscape 8.0 and later Windows Macintosh
Step 2: Setup JavaScript to call from ActionScript Making the call Mozilla 1.7.5 and later Windows Macintosh
Firefox 1.0 and later Windows Macintosh
<html> …
public class ExternalInterfaceExample extends Sprite Safari 1.3 and later Macintosh
... {
<script> …
function updateForm(name, city, state) private function updateHTMLForm() To check if it is available use the isAvailable() method
{ {
name.innerHtml = name; var result:Boolean = public class ExternalInterfaceExample extends Sprite
city.innerHtml = city; ExternalInterface.call( {
state.innerHtml = state; “updateForm”, “Bob”, “Las Vegas”, public function ExternalInterfaceExample()
return true; “Nevada”); {
} if (ExternalInterface.isAvailable())
</script> if (result) …
… … }
} }
</html> …
11 12
2006 Adobe Systems Incorporated. All Rights Reserved. 2006 Adobe Systems Incorporated. All Rights Reserved.
2
Demo ExternalInterface
JavaScript
1 2 3
> PLACE HOLDER FOR IMAGES OF DEMO <
1 2
Fails
ActionScript
13 14
2006 Adobe Systems Incorporated. All Rights Reserved. 2006 Adobe Systems Incorporated. All Rights Reserved.
ExternalInterface ExternalInterface
1 2 3
JavaScript Exception
15 16
2006 Adobe Systems Incorporated. All Rights Reserved. 2006 Adobe Systems Incorporated. All Rights Reserved.
17 18
2006 Adobe Systems Incorporated. All Rights Reserved. 2006 Adobe Systems Incorporated. All Rights Reserved.
3
FlexAjaxBridge (“the easy way”) Data Integration
Server
Client
Browser Server
JavaScript ASP
SOAP
<html>
… CFM
AMF/RTMP
<script> JSP
FlashPlayer (swf) XML Sockets
…
FABridge.flash.releaseASObjects(); Binary Sockets PHP
…
</script> J2EE, .NET
…
MySQL/MSSQL
</html>
19 20
2006 Adobe Systems Incorporated. All Rights Reserved. 2006 Adobe Systems Incorporated. All Rights Reserved.
Flex Data Management Services (FDMS) Ajax Client for Flex Data Services (ACFDS)
Ajax Bridge for Data Services provides access from JavaScript for messaging
Rich Client and data management services.
Applications
Domain
Model/Persistent Step 1: Load FDMSBridge into HTML page
Store
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
Flex Data Management
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
Services
<title>Products</title>
<link href="css/accordion.css" rel="stylesheet" type="text/css" />
<link href="../css/screen.css" rel="stylesheet" type="text/css" />
FDMS provides rich client applications with rich data functionality. <script type="text/javascript" src="include/FABridge.js“ />
<script type="text/javascript" src="include/FDMSLib.js“ />
Built on a robust messaging architecture
</head>
Automates data synchronization between client and server <body>
Real-time data push <script>
Occasionally connected clients FDMSLibrary.load("/ajax/Products/FDMSBridge.swf", fdmsLibraryReady);
Conflict detection, notification, and resolution
</script>
…
Clustering for fail over and load balancing
Publish/Subscribe messaging
21 22
2006 Adobe Systems Incorporated. All Rights Reserved. 2006 Adobe Systems Incorporated. All Rights Reserved.
Ajax Client for Flex Data Services (ACFDS) Ajax Client for Flex Data Services (ACFDS)
Use the data services API similarly to how it is in Flex. Remote requests are asynchronous
Step 2: Request data from the remote destination Step 3: Update HTML elements with retrieved data
23 24
2006 Adobe Systems Incorporated. All Rights Reserved. 2006 Adobe Systems Incorporated. All Rights Reserved.
4
Demo Ajax Client for Flex Data Services (ACFDS)
<html xmlns="http://www.w3.org/1999/xhtml">
…
</body>
<html xmlns="http://www.w3.org/1999/xhtml">
> PLACE HOLDER FOR IMAGES OF DEMO < <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>2006 MAX - AJAX Songs Demo</title>
<link href="SongsDemo.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="includes/spry.js"></script>
<script type="text/javascript">
var dsTopSongs = new FDMSDataSet(“Songs");
dsTopSongs.setColumnType("rank", "number");
</script>
</head>
<body>
…
</body>
</html>
25 26
2006 Adobe Systems Incorporated. All Rights Reserved. 2006 Adobe Systems Incorporated. All Rights Reserved.
27
2006 Adobe Systems Incorporated. All Rights Reserved.