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 1 comment

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:

How to launch Flex debug session via keyboard shortcut on mac

July 29th, 2008 markledford 5 comments

 
OMG. For over 2 years I’ve launched Flex by mousing over to the little bug icon and clicking. I’ve done it so often its become second nature. All because I took one look at this cryptic glyph sequence, tried to guess..tecute it, then gave up to pretend this shortcut didn’t exist.

After a brief stint back in the Flash IDE–instantly returnign to hitting command-enter to debug, I came back to Flex with the determination to slay this gnarly shortcut sequence once and for all. And here’s the secret:

That up arrow icon is shift.  Thats an easy one. The bizzare serif-X-with-one-leg-missing glyph represents alt/option. Yeah I don’t understand that either. Then there’s the letter “D” and “F”. Naturally, hitting all 4 together does nothing. But wait, see the slight excess kerning between those 2 letters? Thats a space. It means let go of the current key combination before hitting the next letter. And there it goes.

Why 4 keys in 2 combinations just to debug your project? Seams a little absurd for one of the most important and common shortcuts. Is every other normal key combination really taken? Really? I’m using the Eclipse plugin version of Flex btw, but I assume its the same with the stand alone.

Did anyone else have trouble with this? Don’t make me feel stupid and annoyed all by myself :P

UPDATE: Figured out how to get the more straight forward command-f11 shortcut working here

Categories: Uncategorized Tags:

Serious (and seriously obscure) bug with flash embed code redirects and variables in IE

July 24th, 2008 markledford 7 comments

Haven’t been posting too frequently, been pretty busy at KickApps working on the Widget Studio. I’d like to write about it in another entry at another time but for now I’d like to help expose a pretty vicious bug we’ve encountered during the course of developing this app.

The Widget Studio is a Flex based WYSIWYG widget generator who’s end product is embed code for widgets. The embed src points to a server side redirect that returns our main SWF file with some variables appended to it. These variables have to be dynamic to pass things like the build version number (cache control) and refferal url to the swf. After much debugging we realized if querystring variables are appended to the redirect in <embed src=”"/> then variables attached to the swf from inside the redirect do not get passed to the SWF in IE.  After much googling, these are the only 2 entries we could find on the matter:

MSDN forum post
JW Player (?) forum post

If both appended-to-redirect and inside-redirect variables are neccessary, the only viable answer is a rest style architecture to pass variables to your SWF (assuming, like in our case, the appended-to-redirect variables can’t be moved to flashVars as they are used by the redirect script itself)

Categories: Uncategorized Tags:

Event.INIT and Event.COMPLETE don’t fire when loading an unpacked swc

July 24th, 2008 markledford No comments

Cleaning out the wordpress there were a few posts I hadn’t finished. This one is mainly a for-future-reference for myself.

I’ve been doing some run-time class loading involving loading SWF files into the same ApplicationDomain as the container via Loader then using getDefinitionByName to access new instances of the loaded classes. I was perplexed that the INIT and COMPLETE events weren’t being dispatched and found some info here.

Categories: Uncategorized Tags: ,

SecurityError: Error #2000: No active security context.

July 24th, 2008 markledford 7 comments

Always interesting to throw an error that has only 4 obscure results in google.
Using setTimeout with navigateToURL:

var urlRequest:URLRequest = new URLRequest("http://google.com");
setTimeout(navigateToURL, 1000, urlRequest, "_blank");

Generates:
SecurityError: Error #2000: No active security context.
at global/flash.net::navigateToURL()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at <anonymous>()
at SetIntervalTimer/onTimer()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()

A work around is to wrap the call in an anonymous function:
setTimeout(function():void { navigateToURL(urlRequest, “_blank”); }, 1000);

Categories: Uncategorized Tags: ,

Fix for Eclipse tab reordering “feature” (MRU tab positioning policy)

March 18th, 2008 markledford No comments

I love using Eclipse for my day to day but I hate how it automatically re-orders my tabs. It looks like other people view the Eclipse “MRU” tab positioning policy as a burden as well.

If you know what I’m talking about and want your tabs to remain where you put them, try installing this Eclipse plugin made to do exactly that: Extended VS Presentation plugin
Its got some other really nice features but check it out and see for yourself.

Categories: Uncategorized Tags: ,

How to make an efficient image proxy

February 21st, 2008 markledford 6 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 markledford No comments

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: ,