PDA

View Full Version : setFocus()


AaronCampbell
10-07-2005, 05:48 PM
I wanted to use setFocus to put the users cursor into a TextInput on frame one. The input has the instance name user. I tried user.setFocus(); but it doesn't work, until the user clicks on the flash movie. Seems like that sort of defeats the purpose :|
Any Ideas?

nix
10-08-2005, 09:20 AM
While I don't know how to do this, but perhaps you know how to integrate flash and Javascript? That way, <body onload="Javascript:flashsetfocusfunction();"> and then in javascript tell it to set focus on the flash. Of course this is completely theoretical. I only know that Javascript works with flash and that if you can set focus on the flash file via JS, you should be able to get it to work. ;)

RysChwith
10-10-2005, 07:39 AM
I don't think it's going to be an issue of making JavaScript work within Flash, as simply getting the focus onto the Flash movie itself. An embedded Flash movie, like anything else, is an object on a web page, and can receive focus. Until it gets focus, a lot of the user controllable stuff doesn't function. So give your <object> tag an ID, then use JavaScript to set the focus on that. The Flash function should then fire as soon as it receives focus.

Rys

AaronCampbell
10-10-2005, 10:25 AM
That's what I thought rys. I have this (generated by flash8...I suppose I could switch to the satay method and try it, but it seems that satay is for nothing more than validating, so it SHOULD work like this right?):<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100%" height="100%" id="picViewer8" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="picViewer8.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="picViewer8.swf" quality="high" bgcolor="#ffffff" width="100%" height="100%" name="picViewer8" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>Then I tried this:<script type="text/javascript">
document.getElementById('picViewer8').focus();
</script>But I just get: Error: document.getElementById("picViewer8").focus is not a function
Source File: http://my.internal.ip/
Line: 15

AaronCampbell
10-10-2005, 10:32 AM
Update: The code in my post above seems to work in IE, but not FireFox etc.

RysChwith
10-10-2005, 12:17 PM
If you have both and object and embed tag, but only have the id on the object tag, that's likely your problem. Firefox is actually rendering the embed tag, not the object tag. With the Satay method, they're both rendering the object tag. Either try it with Satay, or give another ID to the embed tag and try to focus on both of them (it might work using the same ID for both, since only one of them gets rendered by either browser).

Rys

AaronCampbell
10-11-2005, 10:41 AM
I've tried both. I tried this:<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100%" height="100%" id="picviewer" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="picViewer8.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="picViewer8.swf" quality="high" bgcolor="#ffffff" width="100%" height="100%" name="picviewer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="pic_viewer" />
</object>
<script type="text/javascript">
document.getElementById('picviewer').focus();
document.picviewer.focus();
document.getElementById('pic_viewer').focus();
document.pic_viewer.focus();
</script>(I even commented out the javascript 1 line at a time, to make sure one bad line wasn't causing the correct line to not run). Then I tried this:<script type="text/javascript">
window.onload=function(){
document.getElementById('picviewer').focus();
document.picviewer.focus();
document.getElementById('pic_viewer').focus();
document.pic_viewer.focus();
}
</script>
</head>
<body>
<object type="application/x-shockwave-flash" data="picViewer8.swf" width="100%" height="100%" id="picviewer" name="pic_viewer">
<param name="movie" value="picViewer8.swf" />
Sorry, you need the Flash Player.
</object>
(Again...trying the JS one line at a time.)
I just can't seem to send focus to it in FireFox.

RysChwith
10-11-2005, 12:40 PM
Hmm. I'm stumped. I see the same question asked on the Macromedia boards, but without an answer (big surprise there). I'll keep my eyes open and let you know if I stumble across anything.

Rys

LAUBO
07-02-2008, 08:29 AM
Hey,

Over two and a half years old... but still very applicable.
I need users to enter their 'username' on the first frame and have an input text which has focus inside flash. As with all the people above, I now simply need flash to be focussed inside the browser. Has anyone ever stumbled upon the actual solution?

Thanks!
Lau,

alencosoft
08-01-2008, 11:56 AM
Here is what I've done that works:

Javascript:

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

// Call from within another function:
thisMovie("FlashObjectID").focus();
thisMovie("FlashObjectID").showFlash(); // showFlash() is an AS3 ExternalInterface call from JS to .swf which establishes the TextInput.setFocus(); method