Archive for the ‘Flash Development’ Category


If your Flash AS3 Facebook API is not working, check these things…

If you are having problems with the Facebook AS3 API, note that there are not only Flash set up requirements but HTML requirements as well. I was having sporadic issues – I could log via Facebook.login() but my callback function would not fire from Facebook.init(). 

First, make sure the following is in your <head> tags:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>

<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>

Next, make sure that you have this below your opening <body> tag:

<div id="fb-root"></div>

And that should do it!

(advice taken from http://code.google.com/p/facebook-actionscript-api/issues/detail?id=395)

Facebook API – getSession() returns NULL due to Oct. 2011 OAuth switch

I was building a new site using my Facebook framework from last year, and suddenly everything no longer worked! After digging around with great frustration I found some documentation from Facebook discussing the issue. Due to the recent OAuth 2.0 requirement, certain methods (such as getSession() ) are now deprecated. In this case, I will now have to use authResponse() calls and FacebookAuthResponse objects instead of FacebookSession objects.

You can read more at the official Facebook post below.

https://developers.facebook.com/blog/post/525/

Flash Builder 4.6 not compatible with Facebook API (1.8.1)

Since upgrading to Flex 4.6 and Flash Player 11, Flash Builder 4.6 has broken the Facebook API because of its new, native JSON class. 

This leaves you a couple of options.

1. Wait for Facebook and publish to 10.3.183
2. Tweak Facebook’s API to use the native class
3. Rename the as3corelib JSON class and continue using it.

I chose option 3 because Facebook used some of the error-catching mechanisms from as3corelib’s JSON classes and I didn’t want to break anything. Also, considering that Facebook is the subject in question, I want to do as little as possible to it because it already breaks on its own.

Note that Flash Builder will not let you refactor com.adobe.serialization.json.JSON because it’s not smart enough to tell it and the default class apart. So you’ll probably want to use the project search and replace feature. I renamed my class to JSONCore.  

Flash: Timeline dynamic TextFields losing formatting with new content?

You may notice that dynamic TextFields originating from the timeline occasionally maintain their formatting and sometimes lose it, even with programmatic fixes. This is because the problem lies in two different places, and this is how to fix it.

First, it is important to know that Flash will reset the formatting for any new text to that TextField’s defaultTextFormat. If you do not set this property you will have to setTextFormat after every time you change the text. Otherwise you will be stuck with defaults that you probably didn’t want. 

Most problems will be solved with this code (and it’s what most people searching Google are probably looking for). I made this static utility method to do all of my timeline TextField formatting to save time and clutter.

public static function formatTextfield(textField:TextField, label:String, html:Boolean = false, align:String = "left"):void {

 var fmt:TextFormat = textField.getTextFormat();  textField.defaultTextFormat = fmt;  textField.autoSize = align;

 if(html){ textField.htmlText = label; } else { textField.text = label; }
}

Here’s the rundown. Collect the TextFormat data before you change anything. Then you set the default to the existing format to take care of any future changes. Then do your text. The end. 

Now this will fix most people’s problems. However, there is another behavior in Flash that you need to be aware of. If there is text with more than one type of formatting in the TextField, Flash will revert to its defaults (which will lose all of your kerning, for example). Also, if there is no text in the field, it will also revert to defaults. I like putting a simple space in my TextFields to keep them looking clean, but as long as you keep it simple (one character is safest), you should be in good shape.

Note that if you are someone who is doing runtime font loading, you do not want to be putting any text from your primary font on the timeline or things can get all sorts of wonky. In this case you’d probably want to do your formatting then switch to a default font and reset the font programmatically.

Solution to Flash Builder SWF’s not showing up in IE9

Tonight I wrestled with the IE9-agator because my SWF would just not show up in the browser no matter how much Javascript or Facebook stuff I removed from my semi-bloated HTML-Template file. I looked around the web and there appears to have been a wave of IE9-related issues with Flash Player 10.x, and unfortunately this is one of them. However, the solve quite easily (yay).

I stumbled upon a solution after reading this bug report ( http://code.google.com/p/swfobject/issues/detail?id=547 ). I tried removing the swfobject.createCSS(); call and what it revealed was something far stupider. Look at the default CSS from Flashbuilder’s HTML-Template below:

<style type=”text/css” media=”screen”>
       html, body    { height:100%; }
       body { margin:0; padding:0; overflow:auto; text-align:center;
              background-color: ${bgcolor}; }   
       object:focus { outline:none; }
       #flashContent { display:none; }
</style>

The line for #flashContent is normally toggled to display:true with all other browsers once everything is honky-dory  (including past versions of IE) but for some reason IE9 does not get the message to do so. If you get rid of this line you may get a millisecond flicker of your alternate text but your SWF will show up!

AS3 — getTextFormat() gives null for all properties!

Ever had this happen? You have an existing text field, and you want to see its textFormat properties. So you do…

var fmt:TextFormat = myTextField.getTextFormat();

Unfortunately, all of the properties (fmt.font, fmt.size, etc.) of fmt are null!

This bug was driving me crazy. What I discovered was that getTextFormat() is basically retarded under two conditions:

1. Your text field is empty and has never had text in it.

2. Your text field is empty, had text in it at some point, and is set to use Single Line.

Under condition #1, you will never be able to pull any TextFormat data out of your text field, even though it technically should be there. In condition #2, you MUST set the text field to multi-line or it will not work.

What is the solution? Put an empty space in your text field before you use it. This seems really dirty but unless you want to dynamically generate all of your fields, this is the gift Adobe has given us :)

Subclipse SVN — Corrupted File or Directory on Windows 7

If you’ve ever had this error:

The file or directory is corrupted and unreadable.
svn: Can’t move ‘xxx\.svn\tmp\entries’ to ‘xxx\.svn\entries’: The file or directory is corrupted and unreadable.

… knowing that all along your computer is not melting down, there’s a simple fix that will keep SVN from exploding on you. Simply navigate to your project’s folder in Explorer and right click it, then go to Properties > Advanced and deselect “Allow files in this folder to have contents indexed in addition to file properties.” And do so for all sub-folders and files.

AS3 Runtime Fonts not displaying — A CS5 Glitch

In the office today, we found a very frustrating bug with Flash CS5 (on Apple OSX, at least) involving runtime shared font libraries. There was an inconsistency between two of our computers, mine and my developer co-worker, in which publishing a library FLA would cause fonts to either work or not work. Theoretically, there should not have been any font-related differences between us because the fonts were being pulled from another file, but it was very clear that his publishes worked and mine did not.

We figured this was either corruption in the FLA, corruption in the fonts, or Flash was bugging out in some manner. What we found was that regardless of whether or not you’re actually embedding glyphs, Flash still takes takes your system fonts into account when publishing. So the difference between my co-worker’s computer and mine was that he had uninstalled the site’s fonts before running Flash and publishing while I had not.

So what’s the fix? You have to disable or uninstall whatever fonts you are loading in via runtime before publishing any file that references them.

Now whether this applies to all cases is unknown at this point, but it is a real problem in this project and possibly with the method of implementation we use.

For your reference, this is the basic framework we used for our runtime font loading.

http://www.mokisystems.com/blog/flash-as3-loading-fonts/

AS3 BlendMode’s not working? This might be why.

If you’ve dynamically set an object’s blending mode and you’re not seeing it take effect, make sure that its container does not have cacheAsBitmap = true. For some reason, cacheAsBitmap disables blending modes for all display objects within it.

AS3 – SoundTransform.volume increment limitations

Here’s a quick tip about SoundTransform.volume — if you are trying to increment the volume of a sound, be aware that there is a limit to how small you can go. Anything above 0.02 is OK, but 0.01 and below will only work some of the time. This can be a real pain if you aren’t careful! So make sure you either keep the values up or use something like the Greensock Tweening Platform to fade your sounds in and out.