Matt W answers;
Take advantage of the dynamic function construction in AS3.
1
2
3
4
5
6
7
8
9
10
11
12 private function myCallbackFunction(e:Event, parameter:String):void
{
//voila, here's your parameter
}
private function addArguments(method:Function, additionalArguments:Array):Function
{
return function(event:Event):void {method.apply(null, [event].concat(additionalArguments));}
}
var parameter:String = "A sentence I want to pass along";
movieClip.addEventListener(Event.COMPLETE, addArguments(myCallbackFunction, [parameter] ) );
Nick Kwiatkowski created a few very interesting posts with video tutorials, he writes; The second I heard about Adobe giving us the ability to create our own extensions to the Flash Platform in AIR 3.0, I was smitten. It was finally a way that we could add our own features and do the things that were high priorities on our lists, but not on Adobe’s. I knew I was looking for features that were one-offs (how many people today really need access to the COM ports), but they were forcing me to do all sorts of weird workarounds like launching proxy applications to do seemingly simple tasks.
AIR 3.0 got released a few weeks ago and I’ve jumped in head first into creating some ANEs (AIR Native Extensions). For those of you who don’t know, ANEs are packaged extensions that contain operating-system specific code (DLLs for Windows, Libraries for MacOS, Java classes for Android and Objective-C for iOS), that allow you to do things that the Flash Player wasn’t able to do.
Unfortunately, Adobe assumed that if you were developing DLLs for Windows, you were going to be using Visual Studio and nothing more. This didn’t make a whole lot of sense in my mind as they’ve been leveraging Eclipse for all of their tooling, and Eclipse does offer some great C/C++ addins. Now, that being said, Visual Studio is by far the more feature-full and hands-down the best editor for enabling these kinds of workflows on Windows. It is, however, very costly and even though Microsoft offers a free versions, it takes over your computer by installing debug versions of most of Microsoft’s shared libraries making your computer slower and more crash prone.
I wanted to use Eclipse’s CDT addin with the standard GCC tooling that is available on pretty much every operating system. By using GCC, I was able to make very portable code that with minimal effort was able to compile on all three of the major OSs (Windows, Mac, Linux). Adobe’s documentation was little help in getting this going (even if you were coding in Visual Studio, there is very little guidance on how to get things setup). I do have to note that with my setup there is one distinct disadvantage — the lack of ability to debug the DLL when it is launched from AIR. You will have to write your own C/C++ harness to do testing on your code in order to test it. If you use the Visual Studio tooling, you CAN debug any DLL while it is running (this is why Microsoft replaces the shared libraries on your system to allow that debugging).
I’ve created a four part video series documenting how to get going creating ANEs. Part 1 covers setting up your environment, including installing CDT, the compiler, and getting Eclipse setup to do your programming. Part 2 covers actually coding the C/C++ code for your Windows DLL. Part 3 covers creating your ANE, and packing up all the stuff needed to make it work. And Part 4 covers how to use your new ANE in an AIR project.
Watch the Video » Part 1 « QueTwos Blog.
Oct 11
6
UPDATE: I have another Drag-and-Drop Revisited post that covers even more drag-and-drop functionality available in Flex 4.
The Flex 4 gods were kind to us developers when they made the great decision to leave the custom drag-and-drop support unchanged. We just do what we’ve always done: detect the user is trying to drag something via
1 | mouseDown |
or
1 | mouseMove |
and then add both
1 | dragEnter |
and
1 | dragDrop |
event handlers to the drop target. So there is nothing in this post that’s not basically identical to Flex 3, except the coolness of FXG (which you can easily mimic with Degrafa in Flex 3).
via Drag-and-Drop in Flex 4 « Saturnboy.
ahillman3 on Stack Overflow wrote this (and won my hero of the day award); OK, the primary focus for your solution is the preloader attribute on a mobile application. See the preloader=“CustomSplashScreen” below:
1 2 3 4 5 6 7 8 | < ?xml version="1.0" encoding="utf-8"?> <s:viewnavigatorapplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" firstView="views.FXGSplashHomeView" preloader="CustomSplashScreen" splashScreenMinimumDisplayTime="3000" applicationDPI="160"> </s:viewnavigatorapplication> |
The CustomSplashScreen extends and overrides the spark.preloaders.SplashScreen class, and the getImageClass function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | package { import mx.core.DPIClassification; import mx.core.mx_internal; import spark.preloaders.SplashScreen; use namespace mx_internal; public class CustomSplashScreen extends SplashScreen { public function CustomSplashScreen() { super(); } override mx_internal function getImageClass(dpi:Number, aspectRatio:String):Class { return Class(splash); } } } |
The splash in the return Class(splash), is a simple fxg file, like so:
1 2 3 4 5 6 7 8 9 10 11 | < ?xml version="1.0" encoding="UTF-8"?> <graphic xmlns="http://ns.adobe.com/fxg/2008" xmlns:d="http://ns.adobe.com/fxg/2008/dt" xmlns:fc="http://ns.adobe.com/flashcatalyst/2009" version="2.0"> <path y="1" data="M 0 10 L 40 10 L 35 0 L 9 15 L 35 30 L 40 20 L 0 20 z"> <fill> <solidcolor color="#0000FF" alpha="0.6"/> </fill> </path> </graphic> |
That’s all there is to it. Have fun!
– Allen
via .
Sep 11
19
Daniel Freeman writes; I’ve had feedback from a few developers wanting a way to combine MadComponents with Flash Builder 4.5 for mobile. I intended MadComponents as a lighweight alternative to using the Flex framework. So while I don’t really like the idea of mixing them – it’s certainly possible to incorporate MadComponents within an MXML layout. All it takes is a few custom component wrappers.
Note: I’ve now put the code for these wrappers into the SVN code repository.

Note: I’ve now put the code for these wrappers into the SVN code repository.
via MobileAppDev.
Daniel Freeman writes; In this final MadComponents tutorial we’re going to look at the third and final Flash Builder 4.5 tutorial (from here), and do it the MadComponents way. Adobe’s Flex Test Drive for Mobile: Build a mobile application in an hour, takes you through building an AMF web service, and then building a mobile client application that connects to that service. We’re going to build the same application using MadComponents.
AMF is a binary format used to serialise ActionScript objects. A binary AMF packet is usually significantly smaller than REST XML or SOAP packet. Hence AMF services are typically much faster.
This tutorial assumes that you have some expertise in building web services, using PHP, Coldfusion, or Java. But if you’d rather do a tutorial where the web service already exists, then have a go at building a twitter client.
We recommend that you first take a look at the first six parts of this tutorial series, which will bring you up-to-speed with using MadComponents.
Read the entire tutorial at MadComponents AMF Service Test Drive for Mobile « MobileAppDev.
dkozar evolved a working method to Authenticate and Authorize a Flex based app datas service call using Zend AMF, he writes;
I’ve been struggling with it, and figured it all out — so, perhaps it could help others.
The authentication is called on the server only if credentials supplied from the client (via the remote procedure call headers). This snippet illustrates the setup of custom auth (these are the last 6 lines of gateway.php script):
1 2 3 4 5 6 | // Handle request $auth = new My_Amf_Auth(); // authentication $server->setAuth($auth); $acl = new Zend_Acl(); // authorization $server->setAcl($acl); echo $server->handle(); |
Now, your custom auth should extend Zend_Amf_Auth_Abstract. Since I want to authenticate users from a database, I bring the Zend_Auth_Adapter_DbTable to play. But since I cannot extend both Zend_Amf_Auth_Abstract and Zend_Auth_Adapter_DbTable, I use a composition:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <?php require_once ('Zend/Amf/Auth/Abstract.php'); /** * AMF auth class by Danko Kozar, dankokozar.com * @author dkozar * */ class My_Amf_Auth extends Zend_Amf_Auth_Abstract { function __construct() { } public function authenticate() { $adapter = My_Db_Adapter::getInstance(); $adapter->setIdentity($this->_username); $adapter->setCredential($this->_password); // the adapter call // you can wrap it into try.. catch and process DB connection errors $result = Zend_Auth::getInstance()->authenticate($adapter); return $result; } } |
Here’s the adapter class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | <?php /** * DB table adapter auth class for AMF by Danko Kozar, dankokozar.com * @author dkozar * Singleton */ class My_Db_Adapter extends Zend_Auth_Adapter_DbTable { protected static $_instance = null; /** * private! * @param My_Db_Adapter $adapter */ public function __construct(Zend_Db_Adapter_Abstract $adapter = null) { if (!$adapter) $adapter = new Zend_Db_Adapter_Mysqli( array( 'dbname' => 'test', 'username' => 'root', 'password' => '') ); parent::__construct($adapter); $this ->setTableName('users') ->setIdentityColumn('username') ->setCredentialColumn('password') ; // just for testing // $this // ->setIdentity('username') // ->setCredential('password') // ; } /** * @return My_Db_Adapter */ public static function getInstance() { if (null === self::$_instance) { self::$_instance = new self(); } return self::$_instance; } public function authenticate() { $_authResult = parent::authenticate(); // NOTE: The point is that $result->_identity is an OBJECT (of type stdClass), NOT string // with Zend_Auth_Adapter_DbTable it is internally accomplished by calling its getResultRowObject() method // It constructs the stdClass with properties named after table attributes // $user = new stdClass(); // $user->role = "administrator"; // $user->username = $_authResult->getIdentity(); $identity = $this->getResultRowObject(); $result = new Zend_Auth_Result($_authResult->getCode(), $identity); return $result; } } |
MyService.php class. Here it is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | <?php /** * PHP service class with authorization * by Danko Kozar, dankokozar.com * @author dkozar * */ class MyService { /** * from zend docs: * If the ACL object is set, and the class being called defines initAcl() method, * this method will be called with the ACL object as an argument. * This method can create additional ACL rules and return TRUE, * or return FALSE if no access control is required for this class. * * @param Zend_Acl $acl * @return boolean */ public function initAcl($acl) { $acl->addRole(new Zend_Acl_Role("administrator")); $acl->addRole(new Zend_Acl_Role("user")); //acl "allow" method takes 3 parameters (role, resource - class name, privileges - it's function name in this class) // administrator $acl->allow('administrator', 'MyService', 'helloWorld'); $acl->allow('administrator', 'MyService', 'getData'); // user $acl->allow('user', 'MyService', 'helloWorld'); $acl->deny('user', 'MyService', 'getData'); //returning true to signal that we want to check privileges before accessing methods of this class //in my tests if we don't return anything it will treat it like we will return false so better return true or false //your intentions will be clear return true; } /** * Hello world method */ public function helloWorld(){ return "Hello world from MyService service"; } /** * * Returns data * @return [int] */ function getData() { $arr = array(1, 2, 3); return $arr; } } ?> |
Note that the authorization is being built dynamically inside the initAcl method.
On the Flex side I have an auto-generated class (MyService) which extends another auto-generated class (_Super_MyService).
The point is that the outer one is auto-generated only once (initially), and you can modify it, without worrying to be overwritten on service regeneration.
There’s a protected property _serviceControl (which is of type RemoteObject) which could be tweaked if needed.
I’m tweaking it by of setting the endpoint (with string read from a client side config in preInitializeService() method). Plus, I’m adding 2 more methods, which expose setCredentials and setRemoteCredentials methods of _serviceControl, so I can acces it from my code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | package services.myservice { public class MyService extends _Super_MyService { /** * Override super.init() to provide any initialization customization if needed. */ protected override function preInitializeService():void { super.preInitializeService(); // Initialization customization goes here _serviceControl.endpoint = "http://localhost/myapp/gateway.php"; } public function setCredentials(username:String, password:String, charset:String=null):void { _serviceControl.setCredentials(username, password, charset); } public function setRemoteCredentials(username:String, password:String, charset:String=null):void { _serviceControl.setRemoteCredentials(username, password, charset); } } } |
So, before calling MyService methods, I’m setting the credentials with setCredentials() method and this runs the authentication on the PHP side:
1 2 3 4 5 | private var service:MyService; .... service = new MyService(); // ServiceLocator.getInstance().getHTTPService("presetLoader"); service.setCredentials("user1", "pass1"); var token:AsyncToken = service.getData(); |
The authentication via Zend_Amf_Server is, by the way, OPTIONAL! Meaning, with no credentials supplied, Zend_Amf_Server will NOT RUN IT. Thus you should rely on Zend_Acl (e.g. roles) to so your permissions and security!
Finally, here’s the MySQL DB table I’ve been using for authentication:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | -- -- Table structure for table `users` -- CREATE TABLE IF NOT EXISTS `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(50) NOT NULL, `password` varchar(32) DEFAULT NULL, `role` varchar(45) DEFAULT NULL, `firstname` varchar(50) DEFAULT NULL, `lastname` varchar(50) DEFAULT NULL, `email` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`), UNIQUE KEY `id_UNIQUE` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ; -- -- Dumping data for table `users` -- INSERT INTO `users` (`id`, `username`, `password`, `role`, `firstname`, `lastname`, `email`) VALUES (1, 'user1', 'pass1', 'administrator', 'Danko', 'Kozar', NULL); |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cheers!
Danko
Sep 11
4
Kevin Schroeder writes; I forget why, but a few days ago I started doing some digging around with authentication in Zend_Amf_Server. I had figured that I would add an adapter to the Zend_Amf_Server::setAuth() method and that would be it.
But I was wrong.
AMF allows for multiple request bodies to be sent at the same time. Of those there are several “special” types of commands. One of those commands is logging in. What this means is that you don’t need a method that logs someone in for you. Zend_Amf_Server handles authentication separately from your service classes.
Authentication for Zend_Amf_Server will generally use a combination of Zend_Auth and Zend_Acl components. Zend_Auth is used to provide the credential verification while Zend_Acl is used to validate that the current user user can access the requested service method. It is actually a relatively trivial task to restrict access to non-logged in users using the method that I will describe here.
The first step in the process is to create an authentication adapter. It really doesn’t matter what you’re using. What matters is that the adapter returns an identity object with a property called “role”. The built in ACL handle expects this to be part of the identity object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | class Auth extends Zend_Amf_Auth_Abstract { const LOGGEDIN_ROLE = 'loggedin'; public function authenticate() { $identity = new stdClass(); $result = Zend_Auth_Result::FAILURE; // Do a proper login, y'all if ($this->_username == 'test' && $this->_password == 'test') { $identity->role = self::LOGGEDIN_ROLE; $result = Zend_Auth_Result::SUCCESS; } else { $identity->role = Zend_Amf_Constants::GUEST_ROLE; } return new Zend_Auth_Result($result, $identity); } } |
The Auth class extends Zend_Amf_Auth_Abstract because Flex seems to require username and passwords as being the only mechanism for passing credentials. The abstract class defines a method that hooks in with the special commands and passes the special credentials to the special adapter. Clearly your authentication mechanism should be better than the one that I put in here, but you’ll get the idea. The most important part is adding the role property to the identity object and passing it to the Zend_Auth_Result object.
Then in your gateway you need to add this adapter as well as create an simple ACL.
1 2 3 4 5 6 7 8 9 10 11 12 | $server = new Zend_Amf_Server(); $server->addDirectory(realpath(__DIR__.'/../services')); $acl = new Zend_Acl(); $acl->addRole(Auth::LOGGEDIN_ROLE); $acl->allow(Auth::LOGGEDIN_ROLE); $server->setAcl($acl); $auth = new Auth(); $server->setAuth($auth); echo $server->handle(); |
This adds the new Auth role to the ACL and says that it has access to everything. Since there is no place where I allow guest access (denoted by Zend_Amf_Constants::GUEST_ROLE in the adapter) guest requests will be denied.
With just this little bit of code you now have a mechanism that will provide restricted access to all of your service objects.
via Kevin Schroeder’s blog — Zend Technologies.
When you show a popup in Flex in a mobile environment, defined as the style “interactionMode” being set to InteractionMode.TOUCH in this context, that is based on a component that does not implement the mx.managers.IFocusManagerContainer interface, you will receive a runtime error when the user taps the control that is to receive focus.
via Flex 4 Examples.
Aug 11
31
Since Flex 4.5, you have had the ability to develop and export your projects as Android, iOS and PlayBook mobile applications that behave as native ones.
You can also export your Flex mobile project as AIR desktop apps. Just open Flash builder, open your project and choose Project > Export release build. You can then export a “Signed AIR package for installation on desktop”, which means a classic .air file. Yesterday, a customer wanted to know how to run a Flex mobile application in a desktop web browser. Of course, I answered “Why would you do this ?”, and he gave me some good reasons.
His mobile application is connected to a CMS on the backend. Administrators of the application will be able to edit the content of the mobiles apps in a web application. Wouldn’t it be nice to get a live preview in the browser ? When you think of it, a Flex mobile project exports a SWF, so we should be able to run it as a web app. Of course, all the AIR APIs such as the accelerometer, or the SQLite access would be disabled, but we could have a live preview.
And it’s always a challenge for a mobile developer to demonstrate their work. Usually, they just record and publish a video of their app.
We’ll see in this tutorial how to create a Flex mobile project with Flash Builder 4.5.1, and how to publish it as a classic web application. Just follow these steps:
Leonardo França writes; Zend AMF is an implementation done in PHP to work with the communication protocol binary AMF (Action Message Format) and is part of ZendFramework. I had to implement a system to upload files that were a little different than what is typically used in Flash, with this feature had to be integrated into the Zend AMF.
Researching a little on the net, found a solution that was simpler than I thought based on that article with a few adjustments.
Begin with our gateway to be used as endpoint in Adobe Flex.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?php require_once 'Zend/Amf/Server.php'; require_once 'Zend/Amf/Exception.php'; require_once 'br/com/leonardofranca/vo/FileVO.php'; require_once 'br/com/leonardofranca/UploadZendAMF.php'; $server = new Zend_Amf_Server(); $server->setProduction(false); $server->setClass('UploadZendAMF'); $server->setClassMap('FileVO',"br.com.leonardofranca.vo.FileVO"); echo($server->handle()); ?> |
Read more at; File uploads with Adobe Flex and Zend AMF — Workflow: Flash.
Aug 11
31
Shine (formely 8hz-MP3) is a simple lightweight C-based MP3 encoder made by LAME developer Gabriel Bouvigne.
Description of Shine on his website:
The goal of this encoder was not quality, but simplicity. I tryed to simplify the encoding process as much as possible. So Shine is then a good starting point when a programmer needs a very simple MP3 encoder
This Alchemy port features:
via flash-kikko.
Aug 11
31
Helper class to write WAV formated audio files. The class expects audio input data in a byte array with samples represented as floats.
The default compressed code is set to PCM. The class resamples and formats the audio samples according to the class properties. The resampling geared for performance and not quality, for best quality use sampling rates that divide/multiple into the desired output
1 | samplingRate |
.
For more information about the WAVE file format see: http://ccrma.stanford.edu/courses/422/projects/WaveFormat/
via WAVWriter.as — ghostcat — AS3 library of generic tools
Here is a very good multi-part tutorial on the ins and outs of mobile client / server development, that adds some quite useful functionality on Android, Apple IOS and Blackberry mobile devices.
In this Test Drive, you are going to create a Flex mobile application that retrieves, displays, and modifies database records (see Figure 1). A Flex application does not connect directly to a remote database. Instead, you connect it to a data service written in your favorite web language (PHP, ColdFusion, Java, or any other server-side technology). You will build the front-end Flex mobile application; the database and the server-side code to manipulate database records is provided for you as a PHP class, a ColdFusion component, or Java classes.
Flash Builder 4.5 has a built-in data paging feature that generates ActionScript code to retrieve data from the database incrementally on demand. For example, suppose your database has thousands of records and you want to fetch only 20 rows at a time and display them in a data grid. When you enable paging for an operation and bind the operation result to a DataGrid control, the first 20 records will be retrieved initially and the next page of records is fetched only when the user requests them—that is, when he or she scrolls the vertical scroll bar of the DataGrid control.
Flash Builder 4.5 lets you enable paging for any type of data service operation including operations on a Remoting service, web service, or HTTP service. This article explains how to enable data paging for a PHP-based Remoting service. After you set up the server environment required for the sample application, you’ll use Flash Builder 4.5 to generate ActionScript service classes and build a Flex application that incrementally retrieves data sets from a database table using the PHP class on the server.
via Adobe Developer Connection.