A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Page focus on embedded SWF on browser load

  1. #1
    Member
    Join Date
    May 2004
    Posts
    57

    Page focus on embedded SWF on browser load

    I have a flash movie where there's a input textfield that needs to have focus so the user can start typing when the page loads (as opposed to clicking in the field first to give the .swf focus).

    So I've read this article:
    http://helpx.adobe.com/flash/kb/give...ded-movie.html

    And it pretty much says, unless you have a play button (which I don't, and isn't an option), then there's no way of doing it (except in IE).

    I've seen a few workarounds that people claim work i.e calling a JavaScript function to force focus/change tab index etc from inside the SWF, but they usually don't work for me/aren't cross-browser.

    Has anyone ever achieved this effect?
    He took daddy's umbrella!

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    This is what you do:

    var aa:TextInput = new TextInput();
    addChild(aa);
    stage.focus = aa;

    It will give focus to the Textfield. However, the user has to click somewhere in the movie to start typing.
    Last edited by cancerinform; 07-25-2012 at 02:44 AM.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Member
    Join Date
    May 2004
    Posts
    57
    Already done that, was just after some way to force the initial movie focus. Thanks for the reply though.

    I wasn't sure if there was some sneaky EI/JavaScript way of doing it...
    He took daddy's umbrella!

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    I am afraid there is not. I also checked Google and tried this and that.

    What you can do is lead the user with text to the focused field.

    var aa:TextInput = new TextInput();
    aa.move(100,100);
    addChild(aa);
    stage.focus = aa;
    aa.text="Start typing here";
    aa.addEventListener(MouseEvent.CLICK, clickHandler);
    function clickHandler(event:Event):void
    {
    if(aa.text=="Start typing here")
    {
    aa.text = "";
    }
    }
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Member
    Join Date
    May 2004
    Posts
    57
    Hmm, unfortunately that will spoil the look of the login text box. Not a big deal for me, but I know others wont like it. Thanks again, though.

    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="utf-8"/>
    	<title>AS2 TextField Focus Test</title>
    	<meta name="description" content="" />
    	
    	<script src="js/swfobject.js"></script>
    	<script>
    	
    function focusOnSWF()
    	{
    		document.getElementById("flashGame").tabIndex = 0;
    		document.getElementById("flashGame").focus();
    	}	
    	
    		var flashvars = {
    		};
    		var params = {
    			menu: "false",
    			scale: "noScale",
    			allowFullscreen: "true",
    			allowScriptAccess: "always",
    			bgcolor: "",
    			wmode: "opaque"
    		};
    		var attributes = {
    			id:"flashGame"
    		};
    		swfobject.embedSWF(
    			"as2test.swf", 
    			"altContent", "100%", "100%", "8.0.0", 
    			"expressInstall.swf", 
    			flashvars, params, attributes); 
    			
    			
    		
    	</script>
    	<style>
    		html, body { height:100%; overflow:hidden; }
    		body { margin:0; }
    	</style>
    </head>
    <body>
    	<div id="altContent">
    		<h1>AS2 TextField Focus Test</h1>
    		<p><a href="http://www.adobe.com/go/getflashplayer">Get Adobe Flash player</a></p>
    	</div>
    </body>
    </html>
    (Then call inside SWF:

    stage.focus = targetTextfield;
    ExternalInterface.call(focusOnSWF); )

    ^ this code works 1st time in IE & Chrome, but not in Firefox. But if I reload the page in firefox, it magically works, even if I didn't focus on the SWF before reloading.

    Doesn't work at all in Opera or in Safari (but then there's that weird opaque bug in Safari, so wasn't expecting much from that browser anyway).

    I guess I should just give up, LOL.
    He took daddy's umbrella!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center