Archive

Archive for the ‘actionscript’ Category

FYI ExternalInterface.available probably doesn’t do what you think

April 22nd, 2010 2 comments

I think the general Flash Dev consensus is if ExternalInterface.available returns true that you can use ExternalInterface in the swf. This is actually not the case as this property does not check if your security sandbox allows you to use javascript. This is an important distinction for things like Flash widgets that can end up on 3rd party destinations like Facebook that re-write allowScriptAccess=”never”. You’ll need to always try/catch these calls to ensure a security sandbox error won’t break your swf. The closest to documentation on this I could find was this cautionary foot note in the docs which does not explicitly mention security sandbox issues:

NOTE The

 ExternalInterface.available

property reports whether the current container is a type that supports ExternalInterface connectivity. It will not tell you if JavaScript is enabled in the current browser.

Categories: actionscript Tags:

mouse events aren’t dispatched for graphics drawn on main display class

January 5th, 2010 1 comment

This is bizarre. It appears the main display object’s graphics object is rendered on Stage and not its own display as in the example above:

In the Actionscript Project published above I have a red square drawn on the graphics of the main Sprite class and a child sprite with a green square and a textfield to the right to trace clicks.
I have MouseEvent.CLICK listeners on stage, main sprite ClickTest, and child Sprite. With mouse children disabled clicking anywhere will report a single MouseEvent.CLICK to stage even though they should be dispatching for both the main display and stage. With mouseChildren enabled the top square will still only trigger the Stage mouse listener but the bottom will correctly trigger the click on the child sprite, main parent ClickTest sprite, and stage showing that the main DisplayObject is participating in the mouse event bubbling.

Thus my conclusion that the main display object’s graphics object is rendered on Stage which can cause a lot of unexpected behavior and confusion.  Your root display class cannot listen to its own display to catch mouse events for its own graphics object. I guess this could make enough sense if the root display object shared its display with the root Stage but as this hierarchy diagram shows, it shouldn’t: http://www.adobe.com/devnet/flash/quickstart/display_list_programming_as3/

I’d consider it one of those bizarre architecture inconsistencies like swfs having references to stage in the constructor when ran stand alone but not when they are loaded into another swf, its just inconsistent and asking for trouble?

Categories: actionscript, bugs Tags:

major Flash Player GC bug converting string to XML

December 20th, 2009 3 comments

When converting a string to XML the memory used by the XML will never free up no matter the references or garbage collection tricks you have up your sleeve.  This is really excruciating when needing to parse large XML files from a Flex or AIR app.

http://bugs.adobe.com/jira/browse/SDK-11982

http://bugs.adobe.com/jira/browse/SDK-11244

http://bugs.adobe.com/jira/browse/FP-599 <- Looks like this issue has been open for well over a year and may be fixed for the next release of Flash Player (apparently not 10.0.42.34 released a few days ago, just checked, perhaps they mean the next full release :/)

UPDATE: Luca in the comments pointed me to an apparent fix they’ve added to AIR 1.5.2 via System.disposeXML(xml) found in the release notes here.

I’ve verified that this new method works like a charm. It seams like a bit of a strange one-off hack that they’ve put it in under System for AIR only but I’m guessing that they wanted to address it quickly for the SDK that needed it most. Hopefully the regular Flash Player fix is coming in the next major update and won’t require this unusual method.

Categories: actionscript, bugs, flex Tags:

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

February 13th, 2009 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: , ,

encodeURIComponent in AS3

December 17th, 2008 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 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: , ,

handy way of removing event listeners via arguments.callee

August 9th, 2008 1 comment

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:

How to make an efficient image proxy

February 21st, 2008 7 comments

So the work I’m currently doing is centered around loading data from different domains. I’ve got a proxy setup to get around pesky crossdomain issues but I’ve been trying to make it a bit dynamic for efficiency’s sake. I only want to proxy if I know for sure that the data isn’t coming from our servers or a server with a crossdomain file in place.

Creating a “smart” proxy with the URLLoader for text content is a piece of cake. Simply listen for the SecurityErrorEvent then run the url through the proxy. Beautifully simple.

For the Loader class its a different story. The Loader class’s contentLoaderInfo doesn’t have a security error event, just an ioError event. Your supposed to use the childAllowsParent property of the contentLoaderInfo to figure out whether you have bitmapData level access. The only problem is you can’t access that property until the Event.COMPLETE event is dispatched despite the livedocs LoaderContext page stating this property is available on ProgressEvent.PROGRESS which will throw a Error #2099: The loading object is not sufficiently loaded to provide this information. at flash.display::LoaderInfo/get childAllowsParent()

I can finagle with the LoaderContext and try/catches all I want but there doesn’t seam to be a creative solution to this problem. The result: I have to load every image that doesn’t have a policy file TWICE. Once to check childAllowsParent, the next to proxy the image. This doesn’t make any sense considering on the same livedocs LoaderContext page it states:

When you call the Loader.load() method with LoaderContext.checkPolicyFile set to true, Flash Player does not begin downloading the specified object in URLRequest.url until it has either successfully downloaded a relevant cross-domain policy file or discovered that no such policy file exists.

I can see the “Error: Request for resource at http://… by requestor from http://… is denied due to lack of policy file permissions.” errors being outputted to the console window but I don’t seam to have a way to catch it in code. Is something as significant as this, really a bug? Can anyone give me a hand?

UPDATE: This does appear to be a bug with proper policy files checking with the Loader class.  The solution: use UILoader for the check, then use Loader with or without proxy. Thanks Brian from picnik.com for the example below in comments.

Categories: actionscript, bugs, help Tags: , ,

Using the “include” directive to update multiple classes

February 6th, 2008 1 comment

I recently subclassed Flex’s Canvas to utilize my own custom scrollbars (what a pain!) and soon found I needed to do the same with the Box container (VBox, HBox). Due to the clean OOP nature of these components my overrides and implementation turned out exactly the same for my CustomScrollBarCanvas and CustomScrollBarBox. After a few refactoring sessions copying and pasting my changes to both subclasses I ended up moving all my code to a separate include file and its worked out beautifully with Flex still checking the code during incremental compile:

public class CustomScrollBarCanvas extends Canvas {
public function CustomScrollBarCanvas(){
super();
}
include “CustomScrollBarImplementation.as”
}

public class CustomScrollBarCanvas extends Box {
public function CustomScrollBarCanvas(){
super();
}
include “CustomScrollBarImplementation.as”
}

The Actionscript “include” directive is useful when you have a variable or several lines of code that are mirrored in several classes and you want to maintain that code in a central file. Flex and other frameworks use it commonly to write out framework version numbers on all their classes explicitly during compile time. Flex also uses it to write out groups of meta style tags by type (TextStyles.as, BorderStyles.as, etc) into the components that use them. Its really quite ingenious for upkeep but really simple to implement. (FYI in AS3 you no longer prepend the include statement with a “#”)

Categories: actionscript, flex Tags: ,

GoogleReader and some great flash / flex blog entries

January 31st, 2008 No comments

Google Reader has been the perfect resource for me to manage all the blogs (flash and otherwise) that I read everyday. I can categorize my feeds by label, view an aggregated feed of those feeds chronologically, and it even keeps track of new entries. I’ve even found some great new flash blogs via its recommendation system (I’m up to 40 now :O).

A couple entries of interest I’ve read lately and wanted to share:

Eric Feminella’s great Quick Tip blog posts:
Using a parameter class instead of an anonymous object to replace unwieldy method parameters
Using fully qualified paths to define custom event constants to avoid conflicts

This one deserves a post of its own when I have some time to really tinker with it but Metal Hurlant who created the AS3 Crypto Library has created an AS3 run-time compiler written in AS3 by porting parts of the Tamarin project’s “esc” compiler. You can create functions and even classes during runtime. Check out the live demo! Its an exciting time to be a flash developer.

Categories: actionscript, flex Tags: