Multipart form data in flash

February 20th, 2009 markledford No comments

Eugene has a handy MultipartURLLoader class to do the leg work of sending multipart form data from flash.

Note that because it uses:
urlRequest.requestHeaders.push( new URLRequestHeader( ‘Cache-Control’, ‘no-cache’ ) );

You may get SecurityError:
Error #2044: Unhandled securityError:. text=Error #2170: Security sandbox violation: http://domain1.com/your.swf cannot send HTTP headers to http://domain2.com/yourscript.php.

You may need to add a variation of <allow-http-request-headers-from domain=”*” headers=”*”/>  to your crossdomain.xml file or comment out that line. I chose the latter as I don’t think its neccessary in a POST call.

Categories: flex Tags:

solved: white rectangular flicker occuring when clicking on buttons in as3 project

February 13th, 2009 markledford No comments

Thanks be to Google and this blog I finally tracked down the cause of a mysterious unsightly rectangular white flicker that occurs when clicking on buttons in some of my projects as of late.  The culprit? Mac Firefox 3 + SWFAddress. Its really an ExternalInterface+Firefox 3 issue but a recent SWFAddress 2.2 release fixes it!

-Build-in fix for the Firefox 3/Mac OSX blinking effect.

Categories: actionscript, bugs Tags: , ,

show full folder paths in Finder on Mac OSX

February 2nd, 2009 markledford No comments

I’ve been using a Mackbook Pro almost exclusively  for development for the last 2+ years and really enjoy it. Adium is by far the best AIM client on any OS and QuickSilver makes interacting with the OS super quick. There are a few weird UI decisions though that irk me on a daily basis though and I finally google’d one for a quick fix. Here’s a quick Terminal command to show full folder paths in Finder folder windows. Now if I could only cut-and-paste in the file system and edit/delete/manage files in file browser dialogue boxes I’d be all set.

Categories: mac Tags:

javascript injection in AS3

January 20th, 2009 markledford No comments

Pretty useful method of storing Javascript inside of a swf for use with ExternalInterface. The novel part is maintaining the formatted Javascript inside of an xml object, check it out here. Thanks to Derek for the link.

Categories: flex Tags:

encodeURIComponent in AS3

December 17th, 2008 markledford No comments

Haven’t posted in awhile. Been Keeping busy here at KickApps and took a 2 week vacation to South Korea. It was awesome :)

I was looking into interfacing with some Facebook APIs today via actionscript and was having some issues passing some nested querystring vars. Turned out using escape() wasn’t enough and encodeURIComponent() did the trick. I didn’t realize it was even available in actionscript until i did some googling. encodeURI() and encodeURIComponent() are available along with escape() as top level functions in AS3.

Here’s a useful link explaining the difference between them.

Categories: actionscript Tags:

mysterious “Where is the debugger or host application running?” dialogue on non-debug swfs

September 1st, 2008 markledford 3 comments

Remember awhile back when you’d go to a flash site and randomly get accosted by a “Where is the debugger or host application running?” modal prompt? Haven’t seen one in a while have you? Happily these days debug swfs normally don’t pop open this dialogue unless you explicitly right click a debug swf and click on “Debugger” from its context menu. Unfortunely there are still some tricky situations where this prompt will still rear its ugly head.

My Google-foo (or Adobe?) has let me down on getting solid information on this but in my tests it appears this functionality changed with Flash Player Debugger 9,0,115,0 (Yeah, I thought it was earlier too). This is the debugger version that installs with Flex so even tho you may no longer get the prompt its keen to note that any viewer with a <9,0,115,0 Flash 9 debugger (like the 9,0,45,0 debugger that installs with Adobe CS3) will still receive it. In most cases this isn’t anything to worry about though as its second nature to turn off debugging on your production swf. However did you know you have to take into account all embedded and run-time loaded swfs as well?

After receiving reports of said infamous debugger on our production swfs and a lot of time spent investigating with Flash Switcher I found a couple insignificant embedded icon swfs and a few run-time loaded font swfs were the debug swf culprits. Duplicating the issue in the Flash 9.0.45.0 Debugger, what made matters worse is that each debug swf that loaded was getting its own modal popup and, atleast in Mac FF3, each consecutive modal popup was showing up blank but still needed to be clicked or the user was locked out of the site.

After another extensive google search the only thing I could find regarding this child swf debugger policy is a brief mention in Tinc Uro’s Blog regarding Flash Player 9 Update 3 (again Player 9,0,115,0). The one line from his release notes was: “210746 When a release swf loads a debug swf, flash player doesn’t look for the debugger”.  I’m assuming that this was the “fix” as this player version does indeed keep the issue from happening. So to prevent your viewers from ever getting spammed with “Where is the debugger” modal windows, ensure all your swfs (embedded and run-time loaded) are non-debug or force your viewers to update to the most recent flash player if they don’t have atleast 9,0,115,0.

With the proliferation of “dot” releases of the Flash Player its now really important to know which sub version of the player you are targeting. Looking at the Flash Player 9 version penetration rates at KickApps I was surprised to find around 80% of our audience had atleast 115. I’m not sure of the remaining 20% how many are debug players though.

Version        Penetration
9,0,124,0:    ~56%
9,0,115,0:    ~24%
9,0,47,0:     ~10%
9,0,28,0:      ~7%
9,0,45,0:      ~4%

Categories: actionscript, bugs Tags: , ,

Why some AS3 swfs work stand alone but fail to load into other swfs

August 13th, 2008 markledford 20 comments

Most developers who create standalone swfs have some standard instantiation code in their class constructor, something like this:

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

This works fine when the swf is embedded on a page directly as the “stage” property will be available instantaneously.
When this swf is loaded into another swf however, say like this:

var loader:Loader = new Loader();
addChild(loader);
loader.load(new URLRequest("http://widget.meebo.com/mcr.swf?id=RQYRkTseLc"));

It generates the infamous and ambiguous: TypeError: Error #1009: Cannot access a property or method of a null object reference.
I’m pretty sure this is because when a swf is loaded into another swf, it’s class constructor is called to create the object before it is even added to it’s parent (the Loader object).
Thus the stage property is undefined, which throws the error, which kills the call stack including what ever else was in the constructor after the stage reference.
I’d kind of consider this a bug in the flash architecture.

The work around to insure your swf is compatible with loading into other swfs:
If the stage references are just the above, you can throw a try/catch around them as they would probably get set by the loader anyways:

try {
   stage.align = StageAlign.TOP_LEFT;
   stage.scaleMode = StageScaleMode.NO_SCALE;
} catch(er:Error) { };

or just ensure the property is available:

if (stage){
   stage.align = StageAlign.TOP_LEFT;
   stage.scaleMode = StageScaleMode.NO_SCALE;
}

or, if there is setup that absolutely requires the stage reference, put this in your constructor:

Constructor(){
   if (stage){
      onAddedToStage();
   } else {
      addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
   }
}

private function onAddedToStage(evt:Event=null):void {
   removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
   stage.align = StageAlign.TOP_LEFT;
   stage.scaleMode = StageScaleMode.NO_SCALE;
   initApp();
}
Categories: flex Tags:

handy way of removing event listeners via arguments.callee

August 9th, 2008 markledford No comments

Theo’s entry reminded me how useful this can be especially when using an anonymous function as a one time callback. Try it out:

stage.addEventListener(MouseEvent.MOUSE_DOWN, function(event:Event):void { event.currentTarget.removeEventListener(event.type, arguments.callee); trace(‘ran once’); });

FYI you should always use event.currentTarget and not event.target when removing a mouse event listener because event.currentTarget will always reference the object that the listener was explicitly attached to. event.target can easily reference a different object like a child displayObject inside the displayObject you were listening for a bubbling event on.

Categories: actionscript Tags:

Fix for when Flex and your debug flash player won’t connect for a debug session

August 6th, 2008 markledford 3 comments

Luckily this guy wasted hours finding a fix to this strange issue so I didn’t have to. Right click on the swf and click on “debugger” in the flash context menu (if the “Where is the debugger or host application running?” pop up isn’t already open). Select the “Other Machine” radio box button and type in “127.0.0.1″.  Voila. Why does this work when “localhost” was already selected by default? No idea but i’ll be getting something done tonight. Thank you guy and your blog.

If this doesn’t  solve your issue and your using Firefox 3 check out this Jira.

Categories: Uncategorized Tags:

How to launch Flex debug session via keyboard shortcut on mac (part deux)

July 30th, 2008 markledford 3 comments

So continuing on this post I took a gander at Flex > Preferences > Keys to get my command-f11 key working… with success! Under the list of keyboard shortcuts about halfway down the “>Category<” column is Run/Debug. The command “Run Last Launched” is mapped to Command-F11 as it should be but under the “When” column it is set to “In Windows”. Not sure what all “In Windows” entails but I edited this shortcut adding a new “When” to this shortcut found under the drop down list called “Editing Flex Source” and bam, functional command-f11. Sure beats the kung-fu move of a keyboard shortcut mentioned in my last entry.

Categories: Uncategorized Tags: