When Flash invokes a Javascript function via GETURL which refers to THIS, what object is THIS pointing to?
January 7, 2005 11:49 AM   RSS feed for this thread Subscribe

When Flash invokes a Javascript function via getURL which refers to this, what object is this pointing to? [More»]
posted by Danelope to computers & internet (5 comments total)
I'm looking for a means by which a Flash object can affect its own presentation without requiring external code, and this doesn't seem to map to a standard DOM object. For example, this bit of ActionScript:

getURL("javascript:this.style.border='4px solid red';");

should produce the intended effect, but simply throws an error claiming this.style is undefined. I am perplexed.
posted by Danelope at 11:52 AM on January 7, 2005


"this" refers to whatever DOM object the script is attached to via a handler (e.g. onClick, onMouseOver, onLoad, etc.). As a URL, that script isn't attached to a DOM object.
posted by kindall at 12:24 PM on January 7, 2005


kindall knows (apparently) more about it than I do, but I can back what he's saying: you can't pass this from an anchor tag for some reason that's probably clearly (and sensibly) delineated in the specs. Well, you can pass it, but it doesn't work the way it does with every other element. In my experience.
posted by yerfatma at 3:14 PM on January 7, 2005


You could assign the Flash object an ID, and then use something like

document.getElementId('flash').style.border = '4px solid red'

(Caveat: I have not testing this...)
posted by Khalad at 4:45 PM on January 7, 2005


window.

When a method is called, 'this' points to the object the method was grabbed from. This is somewhat odd as it means that unlike in many programming languages:

object.foo();

behaves differently to:

var boing= object.foo;
boing();

If the case like this where 'boing' is called as a function instead of a method, 'this' doesn't get assigned to any object, so it's the global object which for a web browser is 'window'.

So, yeah, forget 'this' and use something along the lines of getElementById.
posted by BobInce at 5:56 PM on January 7, 2005


« Older How do you stay focused on a p...   |   Where does Falun Gong get all ... Newer »

You are not logged in, either login or create an account to post comments



Related Questions
Flash or Java player to play most internet audio... December 1, 2007
Scrolling Sideways August 30, 2007
I want to program a board game. June 17, 2007
looking for web image rotator that does text captions August 18, 2006
Help Me Teach Programming July 18, 2005