Math calculations in Flash return wrong number with lots of decimals...

...In other words, a Floating Point Error, or so my web research says.

Apparently, in all coding languages (not just Flash), a decimal does not have an exact representation in binary. So, for example, 5.100000000000000001 is seen as close enough to 5.1. This is fine when doing other things, such as moving a Movie Clip to an x position, but if you are coding something such as a calculator when you need to display the exact number, it can be frustrating.

I found a method online that corrects this by comparing a few numbers, and estimating. Seems to do the trick in my case.


Firebug and Flash Video

I haven't officially confirmed this yet, but I think I've found the reason why my Flash Video was frequently pausing and skipping mid-stream. I thought it was just the Mac-doesn't-like-Flash-Video thing, but I think it was actually mostly due to Firebug. After disabling it, video seemed to work much better.


X and Y positions inaccurate after startDrag with boundaries set.

Working with a recent project, I had to create a pseudo swipe on a nav bar button (CS5 was not available). So I put a listener on the button which would detect the MOUSE_DOWN and MOUSE_UP positions, and compare the difference of the mouse x/y positions to see if there was a swipe. Because the button was within a nav bar that had to be scrolled, the button had a startDrag() attached to it so it could move up and down while detecting if there was a left/right swipe.

However, once I added that startDrag() method, the x and y co-ordinates started giving me inaccurate results. If you try the following code, you will see that the x/y positions traced are exactly the same at the start and end of the click, even if myBox has been dragged 100 pixels.

import flash.events.MouseEvent;

var myBox:Sprite = this.getChildByName("myBox") as Sprite;
myBox.addEventListener(MouseEvent.MOUSE_DOWN, boxDownHandler, false, 0, true);
stage.addEventListener(MouseEvent.MOUSE_UP, boxUpHandler, false, 0, true);

function boxDownHandler($evt:MouseEvent):void{
	myBox.startDrag(false, new Rectangle(0,100,0,100));
	trace("STARTING MOUSE POS:", stage.mouseX, myBox.mouseY);
}

function boxUpHandler($evt:MouseEvent):void{
	myBox.stopDrag();

	trace("ENDING MOUSE POS:", stage.mouseX, myBox.mouseY)
}

I never figured out why it wasn't allowing me to get the x/y positions of the mouse, considering it was independent of the clip being dragged. However, I found a workaround. If you simply get the mouseX and mouseY position while the box is being moved, and ignore the result at the end, it gives you accurate results that you can use.

import flash.events.MouseEvent;

var myBox:Sprite = this.getChildByName("myBox") as Sprite;
myBox.addEventListener(MouseEvent.MOUSE_DOWN, boxDownHandler, false, 0, true);
stage.addEventListener(MouseEvent.MOUSE_UP, boxUpHandler, false, 0, true);

function boxDownHandler($evt:MouseEvent):void{
	myBox.startDrag(false, new Rectangle(0,100,0,100));
	trace("STARTING MOUSE POS:", stage.mouseX, myBox.mouseY);
	myBox.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler, false, 0, true);
}

function boxUpHandler($evt:MouseEvent):void{
	myBox.stopDrag();
	myBox.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
	trace("ENDING MOUSE POS:", stage.mouseX, myBox.mouseY)
}

function mouseMoveHandler($evt:MouseEvent):void{
	trace("MOVING MOUSE POS:", stage.mouseX, myBox.mouseY)
}

Flash CS5 exporting causing "Error opening URL" error

I recently upgraded to CS5. Maybe that as a stupid thing to do before the first upgrade was released... As usual, there are a list of bugs. One of which, it turns out, does not allow me to work.

When exporting any FLA, including a brand new one with no code whatsoever, I get an "Error opening URL" error. It seems Flash is trying to find the SWF I am trying to export, and is getting lost.

After deleting my preferences, reinstalling, checking forums, and all the other regular things you do to fix a bug, I gave Adobe Support a call. After an hour of getting to the right person, trying to explain to him the problem, and setting up screen sharing, it turns out File Vault needs to be turned off in order to export a SWF. I tested this by creating a new user account, and everything worked fine. It also fixed the issue with Dreamweaver CS5 not opening at all.

I can't go without security, so looks like I will have to use CS4 until Adobe comes out with a fix.

Hard to believe Adobe wouldn't have tested this before releasing.

---UPDATE
Adobe seems to have fixed this. See blog post for more info


I never thought I would say this... Steve Jobs is a douchebag.

For the first time in 15 years, I am considering buying a Windows machine. Apple is becoming like Microsoft was in 1990. Not letting third party developer API's to develop for the iPhone is just pure crap. I truly hope they realize how many people they are pissing off - not just Flash developers - and re-write the new iPhone 4.0 SDK agreement.

This link pretty much sums up how I feel as well

Flash aside, any developer should be posting their disagreement with this. To quote the Facebook "I'm with Adobe" group - "Apple has proven themselves to be anti-competition, anti-developer, and anti-consumer".


Flash vs HTML5, and the death of Flash - My own take

Anyone want an interesting read? Check out the comments on this article on Lee Brimlow's blog website.

It started off talking about the lack of Flash support of the iPhone, and quickly degraded into name calling from the Flash-Sucks side to the Flash-Rules side, and back again. While most of the arguments are truly interesting, I also found it amazing as to how passionate the debate became. Full props to Lee for being able to moderate what I'm guessing was not a fun job.

Being a Flash developer, one might think I am biased; but my take for what it's worth, is that although it is inevitable that any language, in time, will give way to more powerful languages, in regards to Flash, that is not eminent.

The arguments against Flash seem to be as follows:

- HTML5 has native Video Support so Flash is no longer needed.
True it does have Video Support. However, even if HTML5 takes over as the standard for Video playing (which is unlikely soon, as battles reminiscent of the 90's browser wars are developing over which video standard to support. Plus, open standards are notorious for taking forever to figure things out), there are still a lot of things that Flash will still be the easiest to do in, as Flash will continue to advance as the browsers fight it out about standards. Yes, you could try to build a walking AT-AT walker in CSS, or have stars dancing (Safari only) around the page using HTML5, but why would you want to? As a true OOP language, which possibly some HTML and CSS developers are afraid to learn, it is so much easier and faster to do it in AS3. Flash is simply capable of more. It isn't just about Video. Try doing any of these in HTML5...

- Flash is a processor hog
In the cases of bad development, yes that is true. But bad development in any language is a processor hog

- Flash is annoying Advertising
Yes, advertising can be annoying. But it is advertising that is the lifeblood of the internet. If Flash disappears, another technology would come along to replace the advertising. Flash right now is the best way to code those advertisements, as it is specifically designed for handling video, interactivity, animation, databases, and everything else you could need for coding and tracking Rich-Media advertisements. And I might add that Apple, despite Steve Job's recent announcement that Flash sucks (I'm paraphrasing of course), uses Flash to display it's commercials on banner ads.

The other thing I would like to mention is that there will always be arguments to use one language over another. Not just Flash vs [insert name of technology here], but in other areas as well. When things like Silverlight and Unity get more popular, Flash will not die. It simply will give a developer more options to choose from depending on the project's needs, the developer preferences, and the language advantages.

Flash is a great option for doing certain things when done right, and will be around for a while to come. .NET does not die because of PHP or Java, or vise versa. They are tools to choose from.


AS2 Video NetConnection stays paused from within a Class

I hate these little gotchyas...

Haven't done AS2 in a while, and have been trying to get a Video object streaming an FLV. The following code worked from the timeline:

var connection_nc:NetConnection = new NetConnection();
connection_nc.connect(null);
_stream_ns = new NetStream(connection_nc);
_owner.videoContainer.attachVideo(_stream_ns);
stream_ns.play("temp.flv");

But when put into a class, the video stayed paused.

Turns out if I move the _stream_ns.play("temp.flv"); line to it's own function within the class, and call it separately, it works fine. Having it in the same function I guess was just too fast for AS2.

So annoying. Let me know if anyone has found another reason/solution.Read more


Ad Servers are the thorns in my bits n' pieces

Have I ever told you about how much I really hate Ad Servers? Each on claiming to have the most perfect, most simple, and of course, propriety system of doing rich media banners. And each time a new one comes along, it's yet another way of uploading, approving, and setting up. And each time, it's learning new ways to code expandables, syncing videos, setting Shared Objects, and setting clickTags.

And it's always far from perfect. Either they don't support AS3, or you cannot preview locally and their upload system always crashes, or you cannot open more then one file at once (or worse, you have to open ALL files at once), or Safari doesn't show TLAs, or the they don't have their code set up in classes, or they never answer your emails when you come up with a question that they can't answer.

Do I blame Adobe for not having a system to make all this work in one way? Or do I continue to blame crappy Ad Servers for having such large egos?

End of rant.