Archive for the ‘Flex Builder 3’ Category

Using Flex UIComponent width and height

Monday, November 24th, 2008

AS you might know, the only way to add Sprite based classes into a Flex project is by adding them to a UIComponent or a subclass of UIComponent. This adds some extra complications. One of these is that UIComponent does not report width and height correctly. If provided with an explicit width and height, the UIComponent’s size will be set to whatever it was when initialised and will not change if, for example, the contents of the component are scaled. This means that whatever contains the component will not respond appropriately. Dynamic sizing doesn’t seem to work at all. (As an aside, I do think that this is rather a poor implementation, since it breaks the existing functionality of DisplayObject)

In order to correctly set the size we need to recreate the DisplayObject functionality in order that from outside the component we can see the changes in size. In order to do that, it’s necessary to understand how UIComponent (and by extension, most of the other Flex components) is set up and handles sizing.
(more…)

swc fix

Wednesday, November 19th, 2008

Seems I was right (well, let’s see shall we…) in my hypothesis regarding swcs in the same folder as the fla. In order to test this, I started up a new Actionscript project in FlexBuilder and created an assets folder. In Flash I opened a new fla, which I saved into the folder and then began to load it up with assets. At 32.4MB and 130 odd symbols (including videos, vector symbols, images and sounds) my swc finally broke and wouldn’t import into Flex properly. I then created a swc folder in Flex Builder and set the fla to import into that folder. Importantly, I also deleted the swc + swf from the assets folder. After recompiling the fla and rebuilding my Flex project, everything magically worked again.

I hope this helps someone out!

swcked witch

Tuesday, November 18th, 2008

Since my unbridled enthusiasm for swcs a few posts ago, I’ve been sharply brought down to earth about just how unreliable they are. I’ve come across a couple of different problems that just defy all logic. While I still think they are by far the best solution for projects where you want to have your assets compiled into the swf, there are some things that will make you want to stop doing Flash development and go take up pig farming instead.

1) Sometimes your swc will just fail. This seems to be in some way related to the number of assets in the fla, but not neccessarily. You’ll know you’ve got this one when the previously fine references to the swc classes suddenly break, as though it can’t find them. Richtextformat has got a full explanation of the “solution” to this problem over on his blog.

2) Your swf can’t find the document class anymore. I have an fla that held all the assets for my Flex based project. I’m compiling this to a swc and then using that as a library. All fine. However, the designer doesn’t have Flex, so he wants to compile directly from the Flash IDE. So, I set up the document class for him. However, when the fla is compiled, nothing appears. No errors, no traces from either the document class or the timeline. Nada. The problem was that I had left Export SWC on in the publish preferences. Unticking Export SWC did nothing however, it required the swc to be deleted. Then, it worked. All I can assume is that Export SWC was generating a duff swc, which in turn was breaking the swf.

The solution workaround hack I’m using is to have 2 flas. One is set up for compilation from the Flash IDE, the other a blank, unsaved fla (as per Mr TextFormat’s instructions) to generate my swc. This is a pain in the arse, let’s be honest. Every time the fla is updated, I have to refresh the swc fla assets and recompile. I guess I could write some kind of jsfl script to do it for me, but I’ve wasted enough time on this already :(

Anyway. It seems that the Export SWC command in CS3 is really broken. I’m going to try on CS4 and see if it’s been fixed. Fingers, toes, tentacles and any other prehensile appendages crossed.

[Update - It seems like this issue only occurs if you are building the swf/swc into the same directory as the fla. I've tried it with a couple of builds to outside the directory, and it seems to be ok - there might also be an issue if the fla is inside the Flex directory structure but I haven't confirmed this. More testing is needed...]

Flash Flex Font Fudging

Tuesday, October 21st, 2008

Yesterday I spent quite a while trying to get some fonts to display correctly in a Flex Actionscript project. The method I normally use is the one I outlined in this post. This method is good because it allows you to embed only the characters you need and has always worked. Except yesterday.

The main difference as far as I could tell was that I was mixing Flex components and Actionscript text fields. The font was displaying in the Flex, but not the Actionscript. I had embedded the font using Flex’s CSS, so I thought maybe it wasn’t being passed over to the flash, so I embedded the font using the method above as well. Still no joy. I then removed the font completely from the Flex, in case it was screwing things up. Again, nothing. At this point I was getting pretty frustrated, as you could imagine. I went back over the Embedding Fonts technote and noticed that it said that only Truetype or bitmap fonts were supported. So I checked the font type. Sure enough, it was Truetype. About an hour later I decided to reinstall the font in case it was corrupted (it was showing fine in the Flex and in the Flash IDE, so I thought it unlikely). When I looked at the actual file in finder, it had the extension .dfont, which apparently is a datafork truetype font. Make no mistake, this is not supported by Actionscript.

So, in the end I installed a simple Truetype version and it worked straight off. No embedding needed in the Actionscript, just the CSS. I haven’t tried out the new font engine in Flex 4/Flash Player 10, but I really, really hope it doesn’t make you jump through quite so many hoops to display some text right.

Back To The Trees! Source

Wednesday, September 24th, 2008

Here’s the source from my last tree experiment. Please note that it’s the source folder from Flex project, but of course you can just use the classes…

If you do use it in a Flex Project, you’ll need to import the playerglobal.swc from Flash for it to work (it uses BezierSegment from the fl.motion package)

get the source code

I should add that this code is far from optimised. The bezier curve class I’m using wasn’t really designed for this, so it is very slow when smoothing as it iterates over all of the points. I’m going to be optimising this soon so keep an eye out!

Back to the trees!

Wednesday, September 24th, 2008

I’ve been having a play with generative trees again. I’ve been meaning for a while to integrate Bezier curves into my trees for some time, but haven’t had the time to update my BezierChain class to make it accept any number of points. Well, in my paid work, I had to do exactly that, so I thought it was time to put them in. Click the link to see the results!

Random trees with Bezier Curves

I’ll post up the source code if anyone is interested…

Racing Game: Moving into the 3rd Dimension

Friday, September 19th, 2008

So far, I’ve been working with Box2D’s debug mode, which provides a really quick way to test out your physics model to make sure it works, but doesn’t exactly look pretty. The next step was to make it look a bit better.
(more…)

Flash assets in Flex? With Code? Strongly typed? Use a SWC!

Thursday, September 18th, 2008

Flash -> File -> Publish settings -> Flash -> Export SWC.
Flex -> Project -> Properties -> Actionscript Build Path -> Library Path -> Add SWC

Done! Strongly typed, auto completing, code intact Flash library assets in Flex!

No messing.

Building a top down racing game Part 1

Tuesday, August 26th, 2008

Currently I’m developing a top down racing game in Flash for a client and thought I’d share the process that I’m going through. I’m not going to be posting any code, as it’s a client project, but I will try to explain how I worked various bits out so you can make your own :)
(more…)

Custom Events in AS3

Sunday, August 3rd, 2008

Just a quick one.

I’d been having troubles with Custom Events, specifically when they were being forwarded. An Event is dispatched, picked up by another class and then redispatched – the problem being that I’d always get a “cannot convert Event to MyCustomEvent” exception unless I typed the incoming event as an Event, which obviously meant that I lost the properties of the CustomEvent. Casting the Event to CustomEvent in the method gave the same result.

The solution is that you must always override the clone method in a custom event. Apparently, when an event is redispatched, it is cloned internally but with a new currentTarget. Something like:

override public function clone():Event
{
return new CustomEvent(type, bubbles, cancelable);
}

will fix the problem.