Archive for the ‘CS3’ Category

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...]

Lightwave -> Papervision3D

Thursday, October 30th, 2008

In this post, I’m going to go through how to get a textured model from Lightwave into Papervision3D. It’s really not as easy as I should be because of the lack of a collada exporter in Lightwave. The title should actually be more like: Lightwave -> wavefront obj file -> Blender -> dae file -> Papervision3D.

I use Lightwave for no other reason than I used to use it back in my Amiga days and since I rarely need to do any 3d work, there seems little point in learning another 3d package when I have so much else to learn :) They have a ‘discovery’ (ie free) edition too.

There are many, many pitfalls in this process, but once you’re aware of them, it doesn’t take long to do. I’m going to assume that you know nothing about Blender (as I did 8 hours ago) but do know how to use Lightwave. If you don’t know either, you might be better off either learning Blender straight off (or Maya). Props to Altered Egg for the details on what to do in Blender. He’s got pictures and stuff, if you need them :) I’m using Lightwave 9 and Blender 2.48
(more…)

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.

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…)

Yahoo AS3 APIs Rock!

Wednesday, May 7th, 2008

Yeah, I know the world and his dog probably know about these already, but I just discovered them ok?!

They pretty much rock!

Get ‘em here

The one I was interested in (watch this space) was the weather API. I downloaded the package, fired up Flex Builder, stuck in a Weather Service instance, some event listeners and told it to get me some weather. Which it did! The whole process took me all of 3 minutes. That’s how it should be :)

Here’s the class I used (the code I used is for Brighton, UK, btw):

package
{
	import flash.display.Sprite;
	import com.yahoo.webapis.weather.*;
	import com.yahoo.webapis.weather.events.*;

	public class WeatherTest extends Sprite
	{
		private var _weatherService:WeatherService;

		public function WeatherTest()
		{
			super();

			_weatherService = new WeatherService();
			_weatherService.addEventListener(WeatherResultEvent.WEATHER_LOADED, onWeatherLoaded);
			_weatherService.addEventListener(WeatherErrorEvent.INVALID_LOCATION, onInvalidLocation);
			_weatherService.addEventListener(WeatherErrorEvent.XML_LOADING, onWeatherXMLError);

			//get all the weather!
			_weatherService.getWeather("UKXX0215", Units.ENGLISH_UNITS);
		}

		private function onWeatherLoaded(event:WeatherResultEvent):void
		{
			trace(event.data)
		}

		private function onInvalidLocation(event:WeatherErrorEvent):void
		{
			trace(event.data);
		}

		private function onWeatherXMLError(event:WeatherErrorEvent):void
		{
			trace(event.data);
		}
	}
}

Simple huh?

There’s also APIs for Answers, Maps, Search, Upcoming. They’re all well documented and logically laid out. Now get out there and start mashing up those feeds!

Embedding fonts in Flex Builder 2 Actionscript projects

Sunday, April 27th, 2008

After spending about 2 hours searching around the ‘net for a way to do this, all I could find were tips for embedding fonts in FB3, which is should be easy enough:

[Embed(source="/Library/Fonts/Arial", fontFamily="foo", mimeType="application/x-font")] public var bar:String;

This is because one of the things that has been added to FB3 (as far as I can tell) is a font manager system. However, I did run across a load of pages with bugs in this method (and you can only use truetype fonts) and it doesn’t help me with FB2.

Eventually I found a page that suggested that I could use fonts embedded in a swf. Embedding fonts from SWF files The relevant Embed tags for actionscript projects are about 3/4 the way down. This works in both FB2 and 3.

Essentially all you do is to drop a text field onto the stage, format it as normal and then publish. In FB put something like this (it doesn’t actually matter where – the embedded font is available throughout your app):

[Embed(source="/assets/swf/arialFontAsset.swf", fontName="Arial")]
var arialPlain:String;
[Embed(source="/assets/swf/arialFontAsset.swf", fontName="ArialBold" fontWeight="bold")]
var arialBold:String;

and Bob’s your embedded font uncle!

casting boolean values from XML

Saturday, April 12th, 2008

This one is kind of logical when you think about it, but it tripped me up for a bit.
When loading Boolean values from XML, you’d think you could do this to get the value:

var myBoolean:Boolean = myXML..myBoolean;

or even explicitly cast like this:

var myBoolean:Boolean = Boolean(myXML..myBoolean);

but this will give you an erroneous reading. What you need to do is:

var myBoolean:Boolean = Boolean(String(myXML..myBoolean));

What is going on here??
Well, when Actionscript does the cast in the first 2 examples, it actually just checks whether the node exists. So if the node exists, you will get true, if it doesn’t you’ll get false. By casting to a String first it means that the cast to Boolean is forced to evaluate the node value, giving you what you expect.

[update] After some further testing, after seeing the comment below, it seems that all 3 versions give you true, no matter what. In fact, (as far as I can tell) it is impossible to correctly cast a Boolean value held in an XML node as true/false to a Boolean variable correctly.

The solution is to either use a ‘0′ or ‘1′ and cast first to a number:

var myBoolean:Boolean = Number(myXML..myBoolean);

or to do a check like:

if (myXML..myBoolean == "true") myBoolean = true
else myBoolean = false;

Repeat: I must not blog at 1am

Flex Builder and SWFObject 2.0

Friday, March 28th, 2008

Thought this might be of some use to some.

I’m working on an as project in Flex Builder, into which I needed to pass variables from SWFObject. Whilst it’s easy enough to overwrite the generated html in the bin folder, it is a bit of a pain, cos that way you lose the debugging/tracing etc.
So, what I discovered is that there is a file called index.template.html in the html-template folder, which is used to generate the html page. Replace this file with a slightly modified SWFObject template, chuck swfobject.js into your html-template folder (and probably the bin folder for good measure) and Bob’s your uncle :)

[update] The previous template was based on the static embed – this meant you couldn’t actually add params!
Dynamic SWFObject template