Tom Lauck’s Deseloper.org

Get Yourself a Flex Application Name

author:

While working with ExternalInterface on a recent Flex project it became a little cumbersome accessing the embedded SWF several times.  This is especially true if there is more than one SWF in a given page. Typing document.getElementById gets old fast as well. Therefore, this issue illustrates the need for core or global methods that can be reused, especially if you aren’t using a framework such as Prototype or jQuery.

When a SWF is embedded into a page, it naturally becomes a part of window.document/document/window (Internet Explorer).

The document is contained by the window object and may contain any number of elements.

Because of this, it is rather simple to access a SWF to pass a method into a Flex app.  The idea is simply to check whether or not the browser is IE (in this example we will use a UA check), then return the element with the appropriate SWF name:

function getSWFApp(appName) {
	if (navigator.appName.indexOf ("Microsoft") !=-1) return window[appName];
	else return document[appName];
}

Of course, there is more than one way to skin a cat. In this case, a more traditional approach:

function getSWFApp(appName) {
	return document.getElementById(appName);
}

Elsewhere in your code you can then pass a method to the SWF using dot syntax just as you would by using document.getElementById:

getSWFApp("ExampleApp").exampleEventName(exampleEventParams);

As an alternative to document.getElementById, returning the object from the document works like a charm. More importantly, a global method to retrieve a SWF saves many keystrokes. As an added bonus, this method can easily be added to the Flex HTML wrapper, thus allowing quick and easy deployment of applications using ExternalInterface.

21 Responses

date: November 28th, 2009

AH! This is the sort of thing I have been looking for. Doing some research for an article. You should add buttons to the bottom of your posts to digg, stumble, etc your content.- Pam

spoken by: Pam @ cyber monday deals

date: July 22nd, 2010

merhaba sitenize girdiğimde menü aşağıya kayıyor firefox kullanıyom. tesekkurler

spoken by: burun estetiği

date: October 17th, 2010

been reading your blog for 3 days. really love your posts. btw i am doing a research about this topic. do you know any other websites or maybe forums in which I might get more info? thanks in advance.

spoken by: Drew Diltz

date: November 28th, 2010

Wal-Mart Cyber Monday Kinect sales Microsoft Flip-Flops on Kinect Computer ‘Hack’: At this time leading to Cyber Monday, Amazon.com o…

spoken by: interior designers toronto

date: June 2nd, 2011

Fantastic weblog, lover! Get Yourself a Flex Application Name | Tom Lauck’s Deseloper.org is basically one thing. We are starting my own quickly and that i will certainly backup aspects of the one you have, lawfully naturally :)

spoken by: what is a hemroid

date: August 31st, 2011

I’ve read this post and if I could I want to suggest you few interesting things or tips. Maybe you can write next articles referring to this article. I want to read even more things about it!

spoken by: Glen Pefanis

date: January 14th, 2012

this was amazing. I dought if anybody else has the same information. thank you very much

spoken by: dorothycooper

date: September 30th, 2015

Helpful info. Lucky me I found your website accidentally, and I am surprised why this twist of fate didn’t happened earlier! I bookmarked it.

spoken by: download music

date: October 2nd, 2015

There a few intriguing points in time in this post but I do not know if every 1 of them center to heart. It is possible to uncover some validity but I’ll take hold opinion until I explore it further. Superb article , thanks so we want much more! Combined with FeedBurner too

spoken by: 15881585160315773216031588160132157815871585157615751578321605161015751607

date: October 5th, 2015

Hello.This post was really motivating, particularly since I was looking for thoughts on this subject last Monday.

spoken by: lost dogs home

date: October 11th, 2015

What your declaring is totally accurate. I know that everybody need to say the exact same issue, but I just believe that you set it in a way that every person can understand. I also appreciate the photos you put in right here. They suit so effectively with what youre trying to say. Im guaranteed youll achieve so many men and women with what youve acquired to say.

spoken by: Willie Step

date: October 11th, 2015

I like this web site so much, saved to favorites .

spoken by: Porn

date: October 21st, 2015

I together with my friends were actually digesting the great secrets and techniques found on your web blog then immediately developed a horrible feeling I had not thanked the blog owner for those strategies. All of the men were for this reason very interested to learn all of them and now have clearly been making the most of those things. I appreciate you for being well considerate and for picking out such very good areas most people are really desperate to be informed on. Our own sincere regret for not saying thanks to you earlier.

spoken by: jual helm sepeda murah

date: October 31st, 2015

I discovered your weblog site on google and check a couple of of your early posts. Continue to maintain up the quite very good operate. I just additional up your RSS feed to my MSN News Reader. Seeking forward to reading far more from you later on!…

spoken by: click

date: November 3rd, 2015

The the next occasion I read a blog, Hopefully so it doesnt disappoint me about this. I am talking about, Yes, it was my choice to read, but I really thought youd have some thing intriguing to express. All I hear is actually plenty of whining about something you could fix in case you ever werent too busy in search of attention.

spoken by: baju lebaran

date: January 2nd, 2016

Excellent article! This some thing that I always choose to see.

spoken by: cleaning company edmonton

date: January 3rd, 2016

Whoa. That was an awesome write-up. Please preserve writing since I love your style.

spoken by: cure diabetes naturally

date: January 22nd, 2016

Thanks for all your efforts which you have put in this. really interesting info.

spoken by: o sureyi kaldir anani sikerim senin

date: January 24th, 2016

I genuinely like reading by way of and I feel this site got some genuinely utilitarian stuff on it! .

spoken by: serwis laptopów gdynia

date: January 26th, 2016

Thanks for all of your work on this web site.

spoken by: an indicator

date: May 22nd, 2016

Very interesting blog. A lot of blogs I see these days don’t really provide anything that I’m interested in, but I’m most definitely interested in this one. Just thought that I would post and let you know.

spoken by: diabetes juvenil

Leave a Reply

Feb 27 2008