There has been some discussion on the RobotLegs AS3 Framework Google Group about the best workflow for launching popups in Flex, so I thought I’d do a quick sample.
The workflow consists of:
A Command to launch the popup (via the Flex PopupManager)
A Mediator that handles events coming from the popup view component
The popup view component’s Mediator also handles closing of the popup and removes itself from the RobotLegs mediatorMap when it’s no longer required.
Note: I should point out that the source for the SWF below includes only some of the RobotLegs framework source-code. To run the source-code, please download the current version of RobotLegs.
Here’s the SWF and sample code. Feel free to use and abuse, no warranties given or implied. View source
After many weeks of hard work the Mastercard Priceless Travel Flex 3 application I’ve been working on has now also gone live. I worked on the project as sole Flex developer / Flex architect, together with a team of talented and enthusiastic people. It was another project I completed for MRM Worldwide in London and I thoroughly enjoyed it as always.
Apart from Flex 3, the project also uses the PureMVC framework. I’ve been using it for a few projects now and have to say that overall I’m very happy with it’s structure. The Priceless Travel application had some major changes applied to it during the development lifecycle and architecturally speaking they were all handled with ease.
The title could do with some improving – what I’m trying to say is that when subclassing UIComponent, any Image component instances need to be given an appropriate width/height. I have overlooked this time and time again, only to find that the image doesn’t appear – because it’s width and height are initialised to zero.
The following code will result in an image with zero width/height, so the image won’t show:
var img:Image = new Image();
img.source = "myfile.jpg";
Solutions:
Assign specific values for width and height:
img.width = 100;
img.height = 100;
Set the ’scaleContent’ property to false – the image will then resize its container automatically, once it has loaded. Note that this technique has no effect if loading image from non-trusted domains!
Use an event listener to detect when the image has finished loading, then assign the correct width and height. Again, this will only work if the image has been loaded from a trusted domain.
img.addEventListener(Event.COMPLETE, onImageComplete);
protected function onImageComplete(evt:Event):void{var img:Image = evt.target as Image;
img.removeEventListener(Event.COMPLETE, onImageComplete);
img.width = img.content.width;
img.height = img.content.height;
}
I’ve mainly blogged about it so I remember the next time I write some code – but maybe it will also help somebody else debug their missing image problems.
Here’s a quick guide on how to get crossdomain access working for SOAP Webservices from Flash and Flex. Obviously you need to allow access to the domain, however it’s more difficult to realise that you also need to allow the SOAP headers to be sent to the foreign server.
Here is an example crossdomain file that does just that – amend to suit your own requirements, the * wildcard is probably not what you need for your production server.
Here’s a little code snippet that allows you to access flashvar parameters inside a custom Flex preloader.
The custom preloader class extends Sprite and implements the IPreloaderDisplay class. Once the Sprite’s ‘root’ property becomes available, you can use the standard AS3 way of accessing flashvars, namely:
var flashvars:Object = root.loaderInfo.parameters;
This code should be used once the ‘root’ property has been initialised – for example in the ‘initialize()’ method defined by the IPreloaderDisplay interface:
Just for reference, compare the above approach with the standard Flex method of accessing flashvar parameters – which becomes possible once the main Application instance has been created:
var flashvars:Object = Application.application.parameters