Rich Rodecker’s blog on flash, flex, actionscript, javascript, and php, with a dash of randomness
Flex
For those unfamiliar: An overview of Flex, FlexBuilder, and the Flex SDK
Apr 4th
I wrote this up for a client, and realized I had given some version of this many times, so since I had it all written out I figured I’d post it here. I was trying to keep it somewhat high-level, as it’s generally targeted towards the non-developers.
Originally there was Flash. Flash was built as an animation tool and followed a timeline-based approach. When i say timeline-based, think of a filmstrip, and how it is made of a strip of individual, consecutive frames….that was the concept behind Flash, to make editing those long sequences of animation easier. If you open up an .fla file, you can clearly see that each layer is made up of consecutive frames…those consecutive frames are collectively referred to as a ‘timeline’.
Eventually, people figured out that they could build really cool stuff in flash, even full-blown applications that didn’t really have too much to do with traditional animation. Eventually the timeline metaphor, more than just becoming irrelevant, started getting in the way. People were building apps based more an an individual screen-based metaphor, and creating each of those screens on individual frames of the timeline could often be a chore.
So, in order to accommodate Flash application developers, as well as developers coming from other languages into Flash development that were getting scared off by Flash’s awkward development environment, the Flex framework and FlexBuilder were created. In general, the Flex framework is a code library of components which help to facilitate building applications that run within Flash Player. FlexBuilder is the Flex IDE (integrated development environment…big term for a code editor with some other development-related features thrown in) offered by Adobe, which really just a specialized build of Eclipse, which is an industry-standard open source IDE.
In addition to (or instead of) using FlexBuilder, the Flex SDK (software development kit) is open source, and it contains the Flex source code library and compiler, so you can develop Flex apps in any IDE. Setting up and using the SDK will provide the same results as using FlexBuilder, but requires more time and effort to set up…so you get all the tools for free, but you have to set them up yourself. That’s the tradeoff to using FlexBuilder where everything is prepackaged and set up for you already.
Flex application are written using a tag-based approach, so Flex apps are generally made up of text files containing a mix of markup that looks like html (this is called mxml), and Actionscript 3 code. When the flex application source code is compiled, the compiler turns the mxml tags are into normal Actionscript 3 code, and a .swf file is produced. That .swf file runs in Flash Player, the same as a .swf file produced from Flash.
AMFEXT doesn’t handle incoming arraycollections
Mar 30th
Ran into an issue today with AMFPHP trying to send an ArrayCollection…it kept choking when trying to decode the collection. I knew this was already possible, but forgot I had installed the php extension AMFEXT, which handles the encoding/decoding for amfphp when it is installed. Turns out that it doesn’t like incoming arraycollections. Disabling the extension fixed my problem, but I would sure like find a way to get them working together.
BorderSkin on top of children
Mar 27th
Sheesh...I just wasted half a day trying to figure out how to get a borderSkin to appear on top of all the children in a custom component I was building. It was a subclass of Canvas, so it was really easy...now that I know, it seems so obvious I want to kick myself. Anyway, you just need to do:
-
override protected function layoutChrome(unscaledWidth:Number,unscaledHeight:Number):void{
-
super.layoutChrome(unscaledWidth, unscaledHeight);
-
-
//move the border in front of the children
-
rawChildren.setChildIndex(rawChildren.getChildByName('border'), rawChildren.numChildren - 1);
-
-
}
Notes on Control Bars in Flex
Mar 21st
Two quick notes related to Control Bars in Flex. First, I was trying to get an ApplicationControlBar to dock to the bottom of the app, which I couldn't get to work. Maybe someone could point out a better solution, but I went with using a DockableToolbar from the awesome flexlib and setting draggable=false.
The other thing is if you want a ControlBar at the top of a panel, you can just actually just use an ApplicationControlBar wrapped in a VBox.
Flex container rounded corners
Mar 19th
Just putting this up there in case anyone else needs it: if you are trying to get rounded corners on your container (like HBox) by setting the cornerRadius style, you need to make sure that you also set the borderStyle to 'solid' or the rounded corners won't render. You can set the borderThicknessProperty to "0" to hide the border.
Detroit-Area AIR developer needed
Mar 19th
If you are in, or can get to, or would like to travel (travel expenses paid) to Detroit next week to work on a small AIR (Flex) project then please leave a comment or shoot me an email.
Client.Error.DeliveryInDoubt
Feb 1st
Finally getting back into using Flex again, and was trying out the Remote Object tutorial here. Everything went fine for the Hello World tutorial, but I kept getting 'Client.Error.DeliveryInDoubt' messages from the PersonService. I read a couple of places that there had been issues with charset handling in amfphp, so spent a bunch of time with that, but still no luck. Then I remembered that I created the php file for HelloWorld in TextMate, and create the 2 php files for the PersonService in Flex Builder. Sure enough, after recreating the php files in TextMate everything worked. I'm not sure if it was an encoding issue, since it seems like both TextMate and FlexBuilder default to utf-8. I did notice that in FB, the preference for 'New Text File Line Delimiter' (under General/Workspace) was set to default, so I changed it to Unix to line up with TextMate.
Then I went out and installed PDT to set up a PHP perspective within FB.
Drag and Drop in Flex
Aug 9th
I was trying to implement drag and drop for a loaded Image today. All I needed to do was move it, and constrain the drag to the parent container, and that's it. In two different books I have on flex, and in the documentation, as well as this tutorial, they talk about implementing drag and drap through a series of steps which include:
- importing the DragManager, Drag Source, and Drag Event classes
- Creating a new DragSource object
- Creating a new proxy image, which is the item that is visibly being dragged
- Setting up another object oto act as as a drop target and handle drag events
After getting 90% complete with that method, I ran across a comment on the Flex LiveDocs which pointed me to the blatantly obvious: you can simply use the startDrag() and stopDrag() methods inherited Sprite.
Durr.
Undefined Numbers in AS 3
Aug 6th
Just ran into this one, trying to set parameters that were typed to number to undefined or null. There are a few datatypes you can't do that with anymore, and Number is 'special' because they cannot be undefined or null, only NaN. Instead of using Number you can use the special * (untyped) designation, and to test for an undefined Number you can use isNaN().
Book Review: The Essential Guide to Flex 2 with Actionscript 3.0
Aug 2nd
I just got done wrapping up (for the most part) the book Flex 2 With Actionscript 3.0. Overall I thought it was a generally gentle introduction into Flex and covered a lot of basic Flex topics pretty well. Using typical Friends of ED 'show me how' (rather than 'read this code') style, the book breezes through topics such as setting up creating projects, working with variables and databinding, containers and components, working with XML, states, and more.
At this point I have two main criticisms of the book, nethier of which should deter anyone considering this book. First, teh book could have used a little better technical review...or at least someone could have made sure that the code examples in the downloads for the book matched what the book was saying. Mostly it was little things, like a chapter's project files would be all lumped in the folder when the books sample code clearly expected a different directory structure, or the supplied XML files not matching up too well with what the code in the books was showing. I also noticed one glaring instance when a function mysteriosuly switched names for no reason.
The other criticism I have is the ColdFusion slant on the book. Nothing against ColdFusion, but I don't use it, and probably won't, ever. Luckily there was only one chapter devoted to Flex / ColdFusion integration, so I pretty much just skipped it.
As far as the title of the book goes, it barely touches on AS3, so if you're really looking for a deeper level of AS-MXML integration then this book might not be for you. While I don't think this book is an 'Essential Guide', I definitely think it's a great book to kick start your intro to Flex.