AIR, Flex / Flash, FMS, PushButton, Game… Developer
Posts tagged Flex
Tip of the Day – Using interactive assets from Flash in Flex
Jan 31st
So for the most part… up to this point I haven’t really needed to use extensive Flash animations within Flex. I mean like most people, I’ve embedded swf assets into my Flex application by using the [Embed] metadata tag. However, using the Embed metadata tag, in my opinion, is for static assets or simple animations… you know… images, animation only swfs, fonts, etc…
Today I found a cool button that I wanted to use in my Flex application.
The button (roll your mouse over me):
The thing about this button is that it has complex roll over and roll out animations. Of course we could create the same thing within Flex using an ActionScript tween class… but some things are better left to the Flash timeline.
So how do we get our button into Flex, with all of its animation and interactivity intact? The answer, my friends, is to use Adobe’s Flex Component Kit.
Doing some research online, it’s not really clear where to get it, or how to use it. According to labs, it’s released within Flex 3… but I don’t have a clue where. So we’re going to do this my way…
Step 1 : Install Adobe Extension Manager 2.1
Obviously, you can skip this step if you already have Extension Manager 2.1 installed.
If you didn’t install the Adobe Extension Manager when you installed your copy of CS4, you can download it here —> Download Adobe Extension Manager
If you already had Adobe Extension Manager installed… just be sure it has been updated to version 2.1.
Download and open up Setup.app

Extension Manager > About Extension Manager

Says 2.1… cool, we’re ready to move on to step 2.
Step 2 : Install the Flex Component Kit
Now we need to go download the extension —> Download the Flex Component Kit (you need an adobe.com account)
All the way at the bottom you’ll find the extension we’re looking for… Flex Component Kit for Flash CS3 Professional (I know it says CS3 and we’re working in CS4, don’t worry)

Once downloaded, unzip and double-click FlexComponentKit.mxp

Read this whole agreement and only if you agree the terms click “Accept”

…how many of you read that?
Okay, you should see this now.

Documentation for this component can be found here —> FCK Docs
Onward!
Step 3 : The Flash Side
Let’s take our button and load it into Flash. We’re going to name it “MyButton”.

Create an AS3 class to handle all of the button interactions we need

package { // MyButton import mx.flash.UIMovieClip; import flash.events.MouseEvent; public class MyButton extends UIMovieClip { public function MyButton() { super(); buttonMode = true; useHandCursor = true; addEventListener(MouseEvent.MOUSE_OVER, onOver); addEventListener(MouseEvent.MOUSE_OUT, onOut); } public function onOver(event:MouseEvent):void { gotoAndPlay(1); } public function onOut(event:MouseEvent):void { gotoAndPlay("end"); } } }
Make sure you have MyButton selected in the Library, and then use Commands > Convert Symbol to Flex Component.

Your output panel will let you know the command worked properly.

Test the movie by pressing ⌘ + enter (ctrl + enter on the PC).

Publish the movie, which creates both a SWF and a SWC file.

Now that we have our SWC file, we’re ready to move into Flex Builder.
Step 4 : The Flex Side
Copy our newly create SWC file into our libs directory.

With the SWC in our libs directory, it will automatically be included in the classpath of our Flex application (see this tip for more information on the libs directory).
The SWC file includes the MyButton class, so we can now write our code:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*" layout="absolute" backgroundColor="0x000000" backgroundGradientAlphas="[0,0]" creationComplete="onReady()"> <mx:Script> <![CDATA[ private function onReady():void { // How to use the custom button in ActionScript /* var button:MyButton = new MyButton(); button.x = 35; button.y = -10; addChild(button); */ // And just for fun makeGrid(); } private function makeGrid():void { var pad:int = 35; var gridWidth:int = 10; var gridHeight:int = 10; var yOffset:int = -45; var xOffset:int = -25; for(var h:int=1; h<=gridHeight; h++) { for(var w:int=1; w<=gridWidth; w++) { var button:MyButton = new MyButton(); button.x = w*pad+xOffset; button.y = h*pad+yOffset; myPanel.addChild(button); } } } ]]> </mx:Script> <mx:Panel id="myPanel" layout="absolute" left="10" right="10" top="10" bottom="10" backgroundColor="#1D1D1D" title="Hey look, I'm a Flex Panel"/> <!-- How to use the custom button in MXML --> <!--<local:MyButton x="-5" y="-10" />--> </mx:Application>
And here’s what it looks like:
Weeeeee…. that’s fun, you can download the source here.
The source there is an Archived Flex project, all you need to do is Import it into Flex Builder and you’re good to go.
That was a long tip, any questions please post them.
My thoughts on today’s Flex Community Forum
Jan 28th
Joan announced yesterday about, A Public Forum For the Flex Community Tomorrow.
There has been some good and bad feedback regarding the open source aspects of the Flex SDK and the team has decided to go out into the community to hear your thoughts. You can call in to air your concerns or share ideas.
Lately there has been a big upheaval throughout the Flex community dealing with the Fx prefixes in Flex 4. I’m not going to get into it here, but long story short… many people in the community aren’t happy about it.
Even though the Flex SDK is “open source”, it is still tightly controlled by Adobe. All of the planning, new features, all the decisions reside within Adobe. There is the Flex Bug System and it accepts feature requests from the community, which they take into account… but let’s face it, it’s a weak solution.
Today, I had the opportunity to attend the forum. It was absolutely a step in the right direction. Sure, they might have ticked some people off… Nobody likes being told, “This is how we are going to do it, and you have no choice”. That’s not what open source software is about. Sure, it might be too late to take the Fx prefix out of Gumbo… but at least Adobe came to their senses and realized that the community is as vested in this technology as they are.
From my own personal experience… there is a certain disappointment that comes when you’ve invested your own time to contribute to the Flex SDK just to have it deferred or ignored. We’re not being paid to build these things. Don’t take this blog post as a complaint about Adobe or the Flex SDK team, it’s not meant to be that at all. I just think that if Adobe trusts more in the community we can build something amazing.
I think it would be a great thing for Adobe to promote select community members… invite them into planning and discussions, assign features and bugs to them, involve them in decision making. I can rattle off a list of people who would love to be involved on that level with the Flex SDK, me being one of them.
I said it during the meeting, and I’ll say it again. The Flex SDK team should realize that even though it’s their full-time job to make this platform the best it can be.. for a lot of us, it’s our full-time job dealing with the decisions that are made.
:: Update ::
The recording is now available.
Additional Links
Jesse Warden’s thoughts on the issue
Tom Chiverton’s thoughts on the talk
Tip of the Day – When to use include
Jan 18th
A little while ago I posed the following question to the flexcoders mailing list,
I just wanted to ping everyone and get their opinion on something. Why would anyone ever want to use the include directive? I’ve recently been working on poorly designed project where at the top of every module there is an “include Header.as” statement that has 30 include statements within it. To give a datagrid additional functionality, you give it an id=”myDataGrid”, and the include statement takes care of the rest. It’s really bad.
I just don’t see a good use for the include statement anymore. In my opinion, it just promotes bad programming practices.
I mean, can’t everything be taken care of using OOP methodologies? Thoughts?
I’d like to thank everyone who responded, you all gave me quite a bit of insight.
After thinking about this for a while now, here is my list of the common reasons people incorrectly use include (include directive).
I have common functionality that I want shared across multiple components.
That’s great that you’re using DRY philosophy! However, it’s much better to combine the DRY philosophy with object-oriented programming practices. Instead of using the include directive, abstract out common functionality into a parent class. Then you can create children of your parent component, and add additional functionality as needed.
I’m building a framework.
Great… don’t use include. See above reason.
I want to use Code-Behind.
Ted Patrick wrote a wonderful post on Code-Behind in Flex 2. He accomplishes Code-Behind, and does so in an object-oriented manner without using include statements.
Adobe doesn’t natively allow multiple inheritance in AS3, and using the include directive is the only way to fake it.
Frankly, if you understand that statement… you’re advanced enough to know what you’re doing, and you don’t need this tip.
== Conclusion ==
There are rare occasions where include is exactly what you need. However, if you still feel you have a valid reason to use the include directive on a regular basis, please leave a comment below and explain yourself.
Tip of the Day – Using Fireworks to skin those Flex Applications
Jan 15th
Today I was going to post about using flashvars and widget development. However, as I started to document the process, it became too much information for a single tip. So I’m going to do a separate post walking you through my widget development process. Now on to today’s tip!
To be honest with you guys, I’ve never really been a huge fan of Fireworks. I’m a Photoshop guy, and I have been since version 5.5 (hooray ImageReady). However, at our last SeaFlex meeting Marty gave a quick introduction into Flex skinning using Fireworks. My eyes were opened! So here is the basic run down of creating Flex skins using Fireworks CS4.
- Within Fireworks go to Commands > Flex Skinning > New Flex Skin

- Select the components you want to skin.

- Skin to your heart’s desire.

- When you’re finished, go to Commands > Flex Skinning > Export Flex Skin

- I created a new folder called testSkin and saved to that.

- Now in Flex Builder. File > Import > Skin Artwork

- Browse to the folder we just exported our assets to.

- Make sure the image to component mappings are correct.

- And…. you’re done.

Amazing.
:: UPDATE ::
Marty just posted a PC (and more in depth version) of the skinning your Flex applications with Fireworks. Read it here!
Tour de Flex… It’s no rubygems, but it’s a start.
Jan 13th
Mike Chambers has a blog post asking, “How can adobe make the as3 learning curve easier”?
As I talked about in my Why YOU should contribute to Flex post, Adobe wants our input. Here they are again asking the community, “What do you think”?
I commented on Mike’s post.
I think that a more centralized component library and delivery system would make the lives of many developers much easier.
Take RubyGems for example. It’s extremely easy for developers to benefit from the work of others. This has increased the value of Ruby in my eyes tenfold.
As a developer, there isn’t a uniform place that I can go check to see if someone has done this before. So I have to scour the net for a while trying to find a solution by looking through blogs, articles, googlecode, etc…
I know there are a few places out there that make this easier. RIAForge, Adobe Developer Connection, Project Sprouts, Adobe TV, flexcoders.
Most of these sites (blogs especially), have a way to externally interact with them. I think that an Adobe sponsored site or program that would allow a developer to quickly see what’s out there would be an amazing asset to brand new ActionScript developer and veterans alike.
However, I didn’t realize until now, that Adobe is already doing this. This dream “site or program” does exist as the Tour de Flex. Which if you haven’t installed yet, I highly recommend it.
As the title of this post says, it’s no rubygems (not yet anyways)… but it’s a start. Go Adobe!
Tip of the Day – Using the libs directory in Flex Builder
Jan 11th
This tip I’m stealing from Amy over on the flexcoders list.
One not so well documented feature of Flex Builder is the use of the libs directory. By default, when you create a new Flex Project, a libs directory is created. So say for example, you want to create a project, and you are planning to use the Cairngorm framework.
All you need to do is copy Cairngorm.swc into your libs directory, and you’re good to go.




