From at Web 09
Dopo 2 anni di assenza torna l’evento Adobe più atteso dagli sviluppatori web, il 26 e 28 Maggio 2009 a Milano e Roma. Visita il sito http://www.fromatoweb.it per ulteriori informazioni.

Dopo 2 anni di assenza torna l’evento Adobe più atteso dagli sviluppatori web, il 26 e 28 Maggio 2009 a Milano e Roma. Visita il sito http://www.fromatoweb.it per ulteriori informazioni.

Avevo l’esigenza di testare dei canali streaming pubblicati da un FMS ed ho implementato questo semplice client con funzionalità di debug di cui allego il codice.
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:WindowedApplication xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute” creationComplete=”{init()}” width=”560″ height=”474″ borderColor=”#1A41C0″ backgroundGradientAlphas=”[1.0, 1.0]” backgroundGradientColors=”[#123BB3, #03097F]“>
<mx:Script>
<![CDATA[
import mx.messaging.channels.AMFChannel;
import mx.utils.ObjectUtil;
private var meta:Object;
public var nc : NetConnection ;
public var ns : NetStream ;
public var video: Video = new Video;
private function init () : void {
nc = new NetConnection ()
nc.objectEncoding = ObjectEncoding.AMF3 ;
nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus ) ;
nc.addEventListener( AsyncErrorEvent.ASYNC_ERROR, onAsyncError ) ;
nc.addEventListener(IOErrorEvent.IO_ERROR, onIOError ) ;
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecError ) ;
nc.connect( "rtmp://www.serverflash.xxx/live/"); // url del server FMS
}
private function onNetStatus ( e : NetStatusEvent ) : void {
var nsClient:Object = {};
nsClient.onMetaData = ns_onMetaData;
nsClient.onCuePoint = ns_onCuePoint;
trace ( e.info.code ) ;
//-- if is connected
if ( e.info.code.indexOf("Success") > -1 ){
ns = new NetStream (nc ) ;
ns.addEventListener(NetStatusEvent.NET_STATUS, onNsStatus )
ns.client = nsClient;
ns.play("myStream"); // nome dello Stream
video = new Video();
video.attachNetStream(ns);
//panelVideo.addChild(video);
uic.addChild(video);
}
}
private function onAsyncError ( e : AsyncErrorEvent ) : void {
trace (e.text ) ;
}
private function onIOError ( e : IOErrorEvent ) : void {
trace ( e.text ) ;
}
private function onSecError ( e : SecurityErrorEvent ) : void {
trace ( e.text ) ;
}
private function onNsStatus ( e : NetStatusEvent ) : void {
trace ( "netstatus------>" + e.info.code ) ;
}
private function ns_onMetaData(item:Object):void {
trace("meta");
meta = item;
video.width = item.width;
video.height = item.height;
//panel.title = "framerate: " + item.framerate;
panel.visible = true;
trace(ObjectUtil.toString(item));
}
private function ns_onCuePoint(item:Object):void {
trace("cue");
}
]]>
</mx:Script>
<mx:Panel id=”panel” visible=”true” horizontalAlign=”center” title=”Video Stream” left=”80″ right=”80″ bottom=”58″ top=”46″>
<mx:UIComponent id=”uic” width=”345″ height=”246″/>
<mx:ControlBar>
<mx:Button label=”Play/Pause” click=”ns.togglePause();” />
<mx:Button label=”Rewind” click=”ns.seek(0); ns.pause();” enabled=”false”/>
</mx:ControlBar>
</mx:Panel>
<mx:Label x=”435″ y=”10″ text=”InfoDesk” color=”#DEF3F7″ fontWeight=”bold” fontSize=”18″/>
</mx:WindowedApplication>
download Libreria flashcrypt
Use for MD5:
import be.boulevart.as2.security.Encryption;
import be.boulevart.as2.security.EncryptionTypes;
var e:Encryption;
e = new Encryption(EncryptionTypes.MD5(), “123244″ , null, null, null, null);
e.calculate();
trace(“String after MD5 calculation: ” + e.getInput() + “\n”);
Full original AS3 example:
package be.boulevart.as3 {
/**
* Encodes and decodes a base64 string.
* @authors Sven Dens – http://www.svendens.com
* @version 0.1
*
* Original Javascript implementation:
* Aardwulf Systems, www.aardwulf.com
* See: http://www.aardwulf.com/tutor/base64/base64.html
*/
import flash.display.MovieClip;
import be.boulevart.as3.security.Encryption;
import be.boulevart.as3.security.EncryptionTypes;public class as3_cryptdemo extends MovieClip {
protected var e:Encryption;
protected var theKey:String = “you’ll never guess”;
protected var str:String = “My super secret string”;public function as3_cryptdemo()
{
trace(”String before encryption: ” + str + “\n”);//RC4 encryption
e = new Encryption(EncryptionTypes.RC4(), str , this.theKey, null, null, null);
e.encrypt();
trace(”String after RC4 encryption: ” + e.getInput());
e.decrypt();
trace(”String after RC4 decryption: ” + e.getInput() + “\n”);//Base8 encryption
e = new Encryption(EncryptionTypes.Base8(), str , null, null, null, null);
e.encode();
trace(”String after Base8 encoding: ” + e.getInput());
e.decode();
trace(”String after Base8 decoding: ” + e.getInput() + “\n”);//Base64 encryption
e = new Encryption(EncryptionTypes.Base64(), str , null, null, null, null);
e.encode();
trace(”String after Base64 encoding: ” + e.getInput());
e.decode();
trace(”String after Base64 decoding: ” + e.getInput() + “\n”);//Goauld calculation
e = new Encryption(EncryptionTypes.Goauld(), str , null, null, null, null);
e.calculate();
trace(”String after Goauld calculation: ” + e.getInput() + “\n”);//MD5 calculation
e = new Encryption(EncryptionTypes.MD5(), str , null, null, null, null);
e.calculate();
trace(”String after MD5 calculation: ” + e.getInput() + “\n”);//ROT13 calculation
e = new Encryption(EncryptionTypes.ROT13(), str , null, null, null, null);
e.calculate();
trace(”String after ROT13 calculation: ” + e.getInput() + “\n”);//SHA1 calculation
e = new Encryption(EncryptionTypes.SHA1(), str , null, null, null, null);
e.calculate();
trace(”String after SHA1 calculation: ” + e.getInput() + “\n”);//LZW compression
/*e = new Encryption(EncryptionTypes.LZW(), str , null, null, null, null);
e.compress();
trace(”String after LZW compression: ” + e.getInput());
e.decompress();
trace(”String after LZW decompression: ” + e.getInput() + “\n”);*///TEA encryption
e = new Encryption(EncryptionTypes.TEA(), str , this.theKey, null, null, null);
e.encrypt();
trace(”String after TEA encryption: ” + e.getInput());
e.decrypt();
trace(”String after TEA decryption: ” + e.getInput() + “\n”);//Rijndael encryption
e = new Encryption(EncryptionTypes.Rijndael(), str , this.theKey, “CBC”, 256, 256);
e.encryptRijndael();
trace(”String after Rijndael encryption: ” + e.getInput());
e.decryptRijndael();
trace(”String after Rijndael decryption: ” + e.getInput() + “\n”);
}
}
}
Full original AS2 example:
import be.boulevart.as2.security.Encryption;
import be.boulevart.as2.security.EncryptionTypes;class be.boulevart.as2.as2_cryptdemo extends MovieClip
{
private var e:Encryption;
private var theKey:String = “you’ll never guess”;
private var str:String = “My super secret string”;public function as2_cryptdemo()
{
trace(”String before encryption: ” + str + “\n”);//RC4 encryption
e = new Encryption(EncryptionTypes.RC4(), str , this.theKey, null, null, null);
e.encrypt();
trace(”String after RC4 encryption: ” + e.getInput());
e.decrypt();
trace(”String after RC4 decryption: ” + e.getInput() + “\n”);//Base8 encryption
e = new Encryption(EncryptionTypes.Base8(), str , null, null, null, null);
e.encode();
trace(”String after Base8 encoding: ” + e.getInput());
e.decode();
trace(”String after Base8 decoding: ” + e.getInput() + “\n”);//Base64 encryption
e = new Encryption(EncryptionTypes.Base64(), str , null, null, null, null);
e.encode();
trace(”String after Base64 encoding: ” + e.getInput());
e.decode();
trace(”String after Base64 decoding: ” + e.getInput() + “\n”);//Goauld calculation
e = new Encryption(EncryptionTypes.Goauld(), str , null, null, null, null);
e.calculate();
trace(”String after Goauld calculation: ” + e.getInput() + “\n”);//MD5 calculation
e = new Encryption(EncryptionTypes.MD5(), str , null, null, null, null);
e.calculate();
trace(”String after MD5 calculation: ” + e.getInput() + “\n”);//ROT13 calculation
e = new Encryption(EncryptionTypes.ROT13(), str , null, null, null, null);
e.calculate();
trace(”String after ROT13 calculation: ” + e.getInput() + “\n”);//SHA1 calculation
e = new Encryption(EncryptionTypes.SHA1(), str , null, null, null, null);
e.calculate();
trace(”String after SHA1 calculation: ” + e.getInput() + “\n”);//LZW compression
e = new Encryption(EncryptionTypes.LZW(), str , null, null, null, null);
e.compress();
trace(”String after LZW compression: ” + e.getInput());
e.decompress();
trace(”String after LZW decompression: ” + e.getInput() + “\n”);//TEA encryption
e = new Encryption(EncryptionTypes.TEA(), str , this.theKey, null, null, null);
e.encrypt();
trace(”String after TEA encryption: ” + e.getInput());
e.decrypt();
trace(”String after TEA decryption: ” + e.getInput() + “\n”);//Rijndael encryption
e = new Encryption(EncryptionTypes.Rijndael(), str , this.theKey, “CBC”, 256, 256);
e.encryptRijndael();
trace(”String after Rijndael encryption: ” + e.getInput());
e.decryptRijndael();
trace(”String after Rijndael decryption: ” + e.getInput() + “\n”);
}
}
One of the most common requests for the Flash team is to provide a Webservice component for Actionscript 3.0 like the one Flash has for Actionscript 2.0. Finally, Flash has provided the features in CS4 to allow users to use any Flex components that does not rely on Flex framework such as Flex WebService component and HTTPService.
In the below example am going to demonstrate how users can use Flex WebService in Flash to get countries names and populate them in a Flash DataGrid component.
1. File > New
2. Select “Flash File (Actionscript 3.0)”.
3. Open the Component panel and drag a DataGrid component to the stage and call it “dg”.
5. File > Publish settings and click on “Flash” tab.

6. Click on “Settings” button to launch “Advance Actionscript 3.0 Settings”

7. Click on the “library path” tab

8. Click on “Browse to SWC file” icon and get the “framwork.swc” and “rpc.swc” from the Flex SDK as follow :
You can download FlexSDK and select the above SWC’s from the following location
“sdks/3.0.0/frameworks/libs/”
9. Open the action panel and import the following:
import mx.rpc.soap.*;
import mx.core.*;
import mx.rpc.events.*;
import fl.data.DataProvider;
10. The following 2 lines of code are required if you are using SDK 3.0.0 but not if you are using higher version of SDK
//The following 2 lines to register class for
//Interface”mx.interface::IResourceManager
var resourceManagerImpl:Object = ApplicationDomain.currentDomain.getDefinition(“mx.resources::ResourceManagerImpl”);
Singleton.registerClass(“mx.resources::IResourceManager”, Class(resourceManagerImpl));
11. Now copy the following and paste below the above 2 line of codes
var foo:WebService = new WebService();
foo.addEventListener(“load”, finishedLoading);
foo.loadWSDL(“http://www.webservicex.net/country.asmx?WSDL”);
var myOperation:Operation;
function finishedLoading(evt:LoadEvent):void
{
myOperation = Operation(foo.getOperation(“GetCountries”));
myOperation.addEventListener(“fault”, wsdlFault);
myOperation.addEventListener(“result”, wsdlResult);
myOperation.send();
}
function wsdlFault(evt:FaultEvent):void
{
trace(evt.fault);
}
function wsdlResult(evt:ResultEvent):void
{
trace(evt.result);
var myResult:Object = evt.result;
var len:Number = myResult.length;
var xml:XML = XML(evt.result);
var dp:DataProvider = new DataProvider(xml);
dg.dataProvider = dp;
}
12. Test Movie and you should get a list of all the countries inside the datagrid :
Here a few of useful tools, framework and library for a fast build of rich internet application with Flex:
Tools
- Flex Builder (Plugin): Adobe® Flex™ Builder™ 2 is an Eclipse™ based IDE for developing rich Internet applications (RIAs) with the Adobe Flex framework.
- Eclipse: an open source community whose projects are focused on building an open development platform
- Ant: a Java-based build tool. In theory, it is kind of like Make, but without Make’s wrinkles.
- Flex Ant Tasks: provide a convenient way to build your Flex projects using an industry-standard build management tool.
- ASDoc: a command-line tool that you can use to create API language reference documentation as HTML pages from the classes in your Flex application.
- Cruise Control: a framework for a continuous build process. It includes, but
is not limited to, plugins for email notification, Ant, and various source control tools.
Frameworks
- Cairngorm: a lightweight yet prescriptive framework for rich Internet application (RIA) development.
- PureMVC: a lightweight framework for creating applications in ActionScript 3, based upon the classic Model-View-Controller design meta-pattern
- Prana: an Inversion of Control (IoC) Container for the Flex Framework
Unit Testing
- FlexUnit: a unit testing framework for Flex and ActionScript 3.0 applications. It mimics the functionality of JUnit, a Java unit testing framework, and comes with a graphical test runner.
- Flex Unit Optional Ant Task: Allows you to hook FlexUnit into a Cruise Control cycle and extract test reports
Libraries
- Corelib: consists of several basic utilities for MD5 hashing, JSON serialization, advanced string and date parsing, and more.
- Flexlib: a community effort to create open source user interface components for Adobe Flex 2
Remote Gateways
- WebORB: facilitates connectivity between rich clients created with Flex, Flash or AJAX and server-side applications developed with .NET, Java, Ruby on Rails, PHP or XML Web Services.
- Fluorine: an open source .NET Flash Remoting Gateway.
- AMFPHP: a free open-source PHP implementation of the Action Message Format(AMF). AMF allows for binary serialization of Action Script (AS2, AS3) native types and objects to be sent to server side services.
- BlazeDS: is the server-based Java remoting and web messaging technology that enables developers to easily connect to back-end distributed data and push data in real-time to Adobe® Flex® and Adobe AIR™ applications for more responsive rich Internet application (RIA) experiences.