LAZIOMATICA – Guida allo Sviluppo Software

La nuova forma del software su misura…

 

Shared Object in Flash Lite per gestire il seriale di un’applicazione

Sezione per il check  dell’autorizzazione:

function loadCompletePrefs (mySO:SharedObject) {

if (0 == mySO.getSize() ) // non è presente l’oggetto nel dispositivo
{
trace(“NO SHARED FOUND”)
// Se size è uguale a 0, è necessario inizializzare i dati:
gotoAndStop(“serial”) // salto alla sezione per impostare i dati..in questo caso l’inserimento del seriale

}
else
{
//mySO.clear();
// Traccia tutti i dati in mySO:
trace(“SHARED FOUND”)
trace( “Prefs:” );
for (var idx in mySO.data) {
trace( ” ” + idx +”: ” + mySO.data[idx] );
if (idx==”md5″) if( mySO.data[idx]==md5)
{
trace(“Autenticazione OK”)
// continua con elaborazione filmato da utente autenticato o autorizzato
}
else trace (“Autenticazione failed”)

}
}
}

// Istanziamo  l’oggetto condiviso:

var Prefs:SharedObject = SharedObject.getLocal(“Prefs”);

SharedObject.addListener( “Prefs”, loadCompletePrefs );

Sezione di scrittura dello SharedObject:

function saveSeriale (mySO:SharedObject) {
mySO.data.name = “Infodemo”;
mySO.data.email = “info@laziomatica.com”;
mySO.data.serial1 = sn01;
mySO.data.serial2 = sn02;
mySO.data.serial3 = sn03;
mySO.data.md5 = md5v;
mySO.flush();
var flushResult = mySO.flush(); // qui salviamo l’oggetto
switch (flushResult) {
case ‘pending’ :
md5.text += “pending”;
break;
case true :
md5.text += “Data was flushed.”;
break;
case false :
md5.text += “Test failed. Data was not flushed.”;
break;
}

}

var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
var keyCodev = Key.getCode();
if (keyCodev == ExtendedKey.SOFT2) {

if (key1.text==sn01 && key2.text==sn02 && key3.text==sn03)
{
md5.text=”OK CHECK”;
_focusRect = false;
//gestiamo lo shared object appena finito il suo recupero…che in questo caso è immediato poichè non esiste

Prefs = SharedObject.getLocal(“Prefs”);

SharedObject.addListener( “Prefs”, saveSeriale );
}
else  md5.text=”NO CHECK”;

}

}

};

// gestore di eventi tastiera
Key.addListener(keyListener);

Questo è tutto.

Filed under : Actionscript 2,Flash CS3,Flash CS4,Flash Lite,MOBILE
By admin
On 28 gennaio 2009
At 13:40
Comments : 0
 
 

Implementing Encryption in AS2 and AS3

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”);
}
}

Filed under : Actionscript 2,Actionscript 3,Flash CS3,Flash CS4
By admin
On 27 gennaio 2009
At 10:41
Comments : 0
 
 

Using Flex Webservice component in Flash CS4

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 :

original link

Filed under : Actionscript 2,Actionscript 3,Flash CS4
By admin
On
At 09:14
Comments : 0
 
 

Flex Developer toolbox

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.

Filed under : Actionscript 3,AIR,Data Remoting,Flex
By admin
On 24 gennaio 2009
At 21:14
Comments : 0
 
 

BlazeDS: Adobe Opensource Data Remoting – Performance Benchmark

Filed under : AIR,Data Remoting,Flex,RIA
By admin
On
At 20:53
Comments : 0
 
 

Flash lite packager for Symbian S60 3rd Edition Platform

SWF2Go Professional enables you to create rich, powerful and engaging Flash Lite applications rapidly by combining the power of Python for S60 and Net60. Making professional class deployment packages is now one-click operation with new redesigned and friendlier user interface.

www.swf2go.com

Filed under : Actionscript 2,Flash CS3,Flash CS4,Flash Lite,MOBILE
By admin
On 18 gennaio 2009
At 19:36
Comments : 0
 
 

Adobe distributable player solution for Flash Lite Application

Distribute in a more simple way your mobile solution

The distributable player solution enables developers to create rich applications for the latest version of Flash Lite and directly distribute their content to millions of open OS smartphones providing a better on-device user experience. The solution mimics the successful Flash Player desktop model of content-triggered downloads for applications (rather than web-browsing). Developers and content providers no longer need to worry about whether the device has the latest Flash Lite runtime.

Original Links:

http://www.adobe.com/devnet/devices/index.html?navID=sell

Filed under : Flash CS3,Flash CS4,Flash Lite,MOBILE
By admin
On
At 19:34
Comments :Commenti disabilitati
 
 

Building an external XML-driven photo gallery in Flash Lite 2.0

In this article how to build an external XML-driven photo gallery in Flash Lite 2.0 like show in figures.The focus of this tutorial is primarily on creating the dynamic list that can load multiple numbers of thumbnails and some text, along with some value assigned to each of these text to be manipulated at the runtime.

Final application

Originale Link:

http://www.adobe.com/devnet/devices/articles/xml_photo_gallery.html

Filed under : Flash CS3,Flash CS4,Flash Lite,MOBILE
By admin
On
At 19:27
Comments : 0
 
 

AS3 – XML Socket & Binary Socket

There are two different types of socket connections possible in ActionScript 3.0: XML socket connections and binary socket connections. An XMLsocket lets you connect to a remote server and create a server connection that remains open until explicitly closed. This lets you exchange XML data between a server and client without having to continually open new server connections. Another benefit of using an XML socket server is that the user doesn’t need to explicitly request data. You can send data from the server without requests, and you can send data to every client connected to the XML socket server.

ActionScript provides a built-in XMLSocket class, which lets you open a continuous connection with a server. This open connection removes latency issues and is commonly used for real-time applications such as chat applications or multiplayer games. A traditional HTTP-based chat solution frequently polls the server and downloads new messages using an HTTP request. In contrast, an XMLSocket chat solution maintains an open connection to the server, which lets the server immediately send incoming messages without a request from the client.
To create a socket connection, you must create a server-side application to wait for the socket connection request and send a response to the SWF file. This type of server-side application can be written in a programming language such as Java, Python, or Perl. To use the XMLSocket class, the server computer must run a daemon that understands the protocol used by the XMLSocket class. The protocol is described in the following list:

* XML messages are sent over a full-duplex TCP/IP stream socket connection.
* Each XML message is a complete XML document, terminated by a zero (0) byte.
* An unlimited number of XML messages can be sent and received over a single XMLSocket connection.

The XMLSocket class cannot tunnel through firewalls automatically because, unlike the Real-Time Messaging Protocol (RTMP), XMLSocket has no HTTP tunneling capability. If you need to use HTTP tunneling, consider using Flash Remoting or Flash Media Server (which supports RTMP) instead.

You can use the XMLSocket.connect() and XMLSocket.send() methods of the XMLSocket class to transfer XML to and from a server over a socket connection. The XMLSocket.connect() method establishes a socket connection with a web server port. The XMLSocket.send() method passes an XML object to the server specified in the socket connection.

When you invoke the XMLSocket.connect() method, Flash Player opens a TCP/IP connection to the server and keeps that connection open until one of the following occurs:

* The XMLSocket.close() method of the XMLSocket class is called.
* No more references to the XMLSocket object exist.
* Flash Player exits.
* The connection is broken (for example, the modem disconnects).

Example of Socket Server in Java:

import java.io.*;
import java.net.*;

class SimpleServer
{
private static SimpleServer server;
ServerSocket socket;
Socket incoming;
BufferedReader readerIn;
PrintStream printOut;

public static void main(String[] args)
{
int port = 8080;

try
{
port = Integer.parseInt(args[0]);
}
catch (ArrayIndexOutOfBoundsException e)
{
// Catch exception and keep going.
}

server = new SimpleServer(port);
}

private SimpleServer(int port)
{
System.out.println(“>> Starting SimpleServer”);
try
{
socket = new ServerSocket(port);
incoming = socket.accept();

readerIn = new BufferedReader(new InputStreamReader(incoming.getInputStream()));
printOut = new PrintStream(incoming.getOutputStream());
printOut.println(“Enter EXIT to exit.\r”);
out(“Enter EXIT to exit.\r”);
boolean done = false;
while (!done)
{
String str = readerIn.readLine();
if (str == null)
{
done = true;
}
else
{
out(“Echo: ” + str + “\r”);
if(str.trim().equals(“EXIT”))
{
done = true;
}
}
incoming.close();
}
}
catch (Exception e)
{
System.out.println(e);
}
}

private void out(String str)
{
printOut.println(str);
System.out.println(str);
}

AS3 snippet code for connect to server:

var xmlsock:XMLSocket = new XMLSocket();
xmlsock.connect(“127.0.0.1″, 8080);
}

to Receive data we add a listener on XMLSOCK:

xmlsock.addEventListener(DataEvent.DATA, onData);
private function onData(event:DataEvent):void
{
trace(“[" + event.type + "] ” + event.data);
}

to Send DATA we use the “send” method and pass an XML object or string:

xmlsock.send(xmlFormattedData);

Filed under : AIR,Flex,RIA
By admin
On 12 gennaio 2009
At 20:58
Comments : 0
 
 

Actionscript 3 MySql Driver – asSQL

asSQL is an Actionscript 3 Mysql Driver aimed towards AIR projects to allow Mysql database connectivity directly from Actionscript.

download from code.google.com

How to Use – example 1:

import com.maclema.mysql.Statement;
import com.maclema.mysql.Connection;
import com.maclema.mysql.ResultSet;
import mx.controls.Alert;
import mx.rpc.AsyncResponder;
import com.maclema.mysql.MySqlToken;
import com.maclema.util.ResultsUtil;

//The MySql Connection
private var con:Connection;

private function onCreationComplete():void {
con = new Connection(“localhost”, 3306, “root”, “”, “assql-test”);
con.addEventListener(Event.CONNECT, handleConnected);
con.connect();
}

private function handleConnected(e:Event):void {
var st:Statement = con.createStatement();

var token:MySqlToken = st.executeQuery(“SELECT * FROM employees”);

token.addResponder(new AsyncResponder(
function(data:Object, token:Object):void {
var rs:ResultSet = ResultSet(data);
Alert.show(“Found ” + rs.size() + ” employees!”);
},

function(info:Object, token:Object):void {
Alert.show(“Error: ” + info);
},

token
));
}

How to Use example 2:

import com.maclema.mysql.Statement;
import com.maclema.mysql.Connection;
import com.maclema.mysql.ResultSet;
import mx.controls.Alert;
import mx.rpc.AsyncResponder;
import com.maclema.mysql.MySqlToken;
import com.maclema.util.ResultsUtil;

//The MySql Connection
private var con:Connection;

private function onCreationComplete():void {
con = new Connection(“localhost”, 3306, “root”, “”, “assql-test”);
con.addEventListener(Event.CONNECT, handleConnected);
con.connect();
}

private function handleConnected(e:Event):void {
getAllEmployees();
}

private function getAllEmployees():void {
var st:Statement = con.createStatement();

var token:MySqlToken = st.executeQuery(“SELECT * FROM employees”);
token.info = “GetAllEmployees”;
token.addResponder(new AsyncResponder(result, fault, token));
}

private function getEmployee(employeeID:int):void {
var st:Statement = con.createStatement();
st.sql = “SELECT * FROM employees WHERE employeeID = ?”;
st.setNumber(1, employeeID);

var token:MySqlToken = st.executeQuery();
token.info = “GetEmployee”;
token.employeeID = employeeID;
token.addResponder(new AsyncResponder(result, fault, token));
}

private function result(data:Object, token:Object):void {
var rs:ResultSet;

if ( token.info == “GetAllEmployees” ) {
rs = ResultSet(data);
Alert.show(“Found ” + rs.size() + ” employees!”);
}
else if ( token.info == “GetEmployee” ) {
rs = ResultSet(data);
if ( rs.next() ) {
Alert.show(“Employee ” + token.employeeID + ” username is ‘” + rs.getString(“username”) + “‘”);
}
else {
Alert.show(“No such employee for id ” + token.employeeID);
}
}
}

private function fault(info:Object, token:Object):void {
Alert.show(token.info + ” Error: ” + info);
}

Filed under : AIR,Flash CS3,Flex,RIA
By admin
On
At 20:46
Comments :Commenti disabilitati