SubClosure

{ Don't Repeat Yourself ! }

Browsing Posts in Flex

amfphp 1.9 annoyance

No comments

I love amfphp but here is one thing that has been annoying me for almost a year now since the release of amfphp 1.9 final.
Whenever I download amfphp for a new project and import it into PHP Eclipse I have to fix this little error first.

Obviously the current amfphp developers aren’t using eclipse.

Lets say you want to call a remote function with Flex’s RemoteObject and in the Response Handler you wish to access some of the variables you used in your calling function. You could use class variables so that they are available in your Response Handler. But thats not always the preferred way.

Another option that I like to use is to define the response handler in your calling Method as a closure. That way you will have access to all variables that are in the scope of the calling method in your handler function.

Here is an example on how to achieve this:

public function callRemoteMethod( myvar:String ):void {

myRemoteObject.myRemoteFunction( myvar ).addResponder(

new ItemResponder(

function(re:ResultEvent, a:AsyncToken ):void {

//the resonder has access to myar

trace(myvar ) ; trace(re.result) ;

},

function(f:FaultEvent, a:AsyncToken):void {

Alert.show(‘An Error occurred’) ;

}

)

) ;

}

I created a simple Joomla! component. It’s purpose is to demonstrate how a Flex Application can be integrated into a component. The Flex Application is communicating with its Joomla! backend through AMFPHP. AMFPHP1.9 is included in this example setup.

You can download and install this component via the Joomla Administration Interface and link a menu item to it, to see it in action.

You can also download the source code for the simple Flex Application to see how it connects to the gateway.

download joomla component

download flex example source code


Here is a screenshot of the installed component:

The Email Validator’s static method validateEmail requires 3 parameters according to the Flex 3.2 API Documentation:

Parameters

validator:EmailValidator — The EmailValidator instance.
value:Object — A field to validate.
baseField:String — Text representation of the subfield specified in the value parameter. For example, if the value parameter specifies value.email, the baseField value is “email”.

I’m wondering  why it is that I have to specify the actual String value of my textfield as value parameter and then also have to specify “text” as baseField.
I would have thought as value I should specify mytextfield and as baseField “text” as it is done in all other places. I find that confusing.
But this method will only work when used like this for example:

var result:Array = EmailValidator.validateEmail( myemailvalidator , mytextfield.text , “text” ) ;

Ever had to choose a new secure password but couldn’t think of anything and ended up using the same old insecure password as always?

Well here is the solution. It comes in form of a little Unix/Linux programm, called pwgen. It automatically generates difficult passwords that are designed to be easily memorized by humans.

This Flex Application is a frontend for pwgen. You can use it to generate as many passwords as you like.

I recently ran into problems when trying to set the currenState property on a component that was part of a TabNavigator.

I had the component as a direct child in the TabNavigator.
Setting the currentState property in the component resulted in Null pointer exceptions in the Flex Framework – RemoveChild Class.

I got around it by first adding a canvas to my TabNavigator and then adding my component inside the canvas. This fixed the problem.

It is because of flex’s deferred instantiation. Flex called the creationComplete handler on my custom component even though its components were not added yet.
Thats why the RemoveChild tag in my states failed.

By first embedding the component into a canvas and then into the TabNavigator, it only created the canvas but not any parts of my component.

A list of the best libraries for Flex and Flash that can save heaps of development time and add extra functionality to your projects.

  • casalib Lots of useful utility classes.
  • as3corelib A collection of utility classes by Adobe for handling encoding and serialization among other things.
  • Mate Framework – my favorite MVC  framework for Flex – it’s based on property injection
  • PureMVC – another great MVC framework, works with flash as well and has ports to many other languages
  • Cairngorm – popular MVC framework for Flex that’s officially supported by Adobe
  • FlexUnit – unit testing framework for flex – essential for test infected developers and professional projects
  • AS3Crypto – add cryptography to your Flash/Flex Applications
  • AlivePDF – lets you create PDF files from within flash and flex
  • Degrafa – Flex Graphics Framework to easily create graphic with mxml tags – awesome
  • TweenLite The easiest to use Tween library out there.
  • Papervision probably the most used 3D library
  • Away3D Another 3D library that some people prefer to Papervision as it is easier to use.
  • Modest Maps – great mapping library for using different map providers – also supports openstreemaps
  • SWFObject very useful to embed flash movies into html pages
  • SWFAddress Takes swfobject one step further and supports deep-linking.
  • Hi-ReS! Stats a class that shows you when your SWF framerate chokes.
  • BIT-101 MinimalComps A set of ActionScript-only UI components for use in non-Flex projects.
  • Underware – not a library but a nice tool that lets you package and download sets of popular libraries
  • Deface – Face detection for AS3
  • FLARManager – tool for augmented reality
  • Discollision – advanced collision detection library fro AS3
  • Flash Camouflage - easily skin Flash Applications with png, jpg, or gif images
  • MojoColors – easy color library for AS3
  • Flint Particle System - the name says it all – create particles in AS3

If you use ant to build and deploy your application,
the scp task comes in quite handy to automatically upload you project to the production server.

In your ant build.xml file you can add a line like this to your target

<scp file=”${zipfile}” todir=”${server.username}:${server.password}@${server.name}:” trust=”true” />

Where ${zipfile}, ${server.username}, etc are properties that where earlier declared
e.g. <property name=”server.name” value=”192.168.0.1″ />

The ant scp task depends on an external library that can be found here.
You need to download the jsch-0.1.42.jar and copy it into your eclipse ant library folder

e.g. /Applications/Adobe\ Flex\ Builder\ 3/plugins/org.apache.ant_1.7.0.v200706080842/lib/

(on mac I had to copy this file to ~/.ant/lib to work )

Important! You need to restart Flex Builder after that.

After that you can run your ant target and the zip file will be uploaded to your server through scp

Flashplayer is using a separate cache to store remote shared libraries ( RSL ) .
It wont be cleared by just emptying the browser cache.

To clear the flashplayer cache go to:
http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager03.html

Uncheck the checkbox: “Store common Flash components to reduce download times”

This will delete the Flashplayer Cache.

After that check it again and done

Get Adobe Flash player