Focus Flash <object><embed> on page load
-
- Posts: 9
- Joined: February 19th, 2005, 5:54 pm
Focus Flash <object><embed> on page load
Many flash movies that use interactive things such as text boxes, want to have focus put on a starting text box on page load. This can be accomplished in IE by having the HTML/JAVASCRIPT code:
<body onLoad="JavaScript: document.getElementById("FLASHID").focus();"> ... or
<body onLoad="JavaScript: document.FLASHID.focus();">
This command does not work in Firefox. Firefox's javascript console actually reports it as an error. Infact, all event methods (focus, blur, click, etc) say they aren't methods when dealing with flash <object><embed> components. However, if you manually click on the flash component, the browser assigns it focus... how can I reproduce this programmatically?
Is there a way to programmatically assign focus to a flash object (component) on page load/event? Something from a flash/javascript developer point of view? Having an Intro "Click Here" frame in the flash movie is not an option.
If anyone has run into this & knows a way around it (or even has an idea) please let me know.
Thanks a lot,
S.
<body onLoad="JavaScript: document.getElementById("FLASHID").focus();"> ... or
<body onLoad="JavaScript: document.FLASHID.focus();">
This command does not work in Firefox. Firefox's javascript console actually reports it as an error. Infact, all event methods (focus, blur, click, etc) say they aren't methods when dealing with flash <object><embed> components. However, if you manually click on the flash component, the browser assigns it focus... how can I reproduce this programmatically?
Is there a way to programmatically assign focus to a flash object (component) on page load/event? Something from a flash/javascript developer point of view? Having an Intro "Click Here" frame in the flash movie is not an option.
If anyone has run into this & knows a way around it (or even has an idea) please let me know.
Thanks a lot,
S.
-
- Posts: 3451
- Joined: November 30th, 2002, 12:30 pm
Both examples are incorrect in that "Javascript:" is not needed (and really shouldn't be there at all) in an event handler.
The second example is incorrect, IE-only syntax. The first is correct.
Why do you need a user action (or a faked programmatic one) to start the movie? Why not just start it when the object loads? What happens if the user doesn't have JavaScript enabled? They will not get that focus, nor will they get any kind of indication of what they're supposed to do.
The second example is incorrect, IE-only syntax. The first is correct.
Why do you need a user action (or a faked programmatic one) to start the movie? Why not just start it when the object loads? What happens if the user doesn't have JavaScript enabled? They will not get that focus, nor will they get any kind of indication of what they're supposed to do.
-
- Posts: 9
- Joined: February 19th, 2005, 5:54 pm
Ignore the JavaScript: then.
I'm building an interactive web application. If the user does not have JavaScript enabled, then nothing will work.. its like saying "what if the user doesn't have flash" - well, then they wont see anything will they.
The movie does start right away. It has a starting sound that plays. But, flash movies are not assigned focus when first loaded. By default, the user has to click on the movie to give it focus.
For specific information, I have a flash movie that has typing. The movie is actually an educational activity for students (as young as kindergarder). When the page loads, it gives audio instructions ("type the word that you see"), and has a word like "CAT". They then retype the word in a box below the word CAT. This needs focus immediately when the page loads. Having any intermediate steps would only complicate things for the kids.
In addition to this, I have functional buttons (re-say instructions, for example) that are seperate flash movies. For IE, whenever these buttons are clicked I have them sending focus back to the main flash movie, that way if they were typing, they could keep typing after clicking the button. It may sound strange, but it is very comfortable, and extremely uncomfortable to have to re-click to give focus back. For the functional buttons (flash movies) I use the code:
<object onFocus="document.getElementById('FLASHID').focus();" ... .... >
Using onCLick would work just the same (and neither will work in Firefox).
Any ideas?
I'm building an interactive web application. If the user does not have JavaScript enabled, then nothing will work.. its like saying "what if the user doesn't have flash" - well, then they wont see anything will they.
The movie does start right away. It has a starting sound that plays. But, flash movies are not assigned focus when first loaded. By default, the user has to click on the movie to give it focus.
For specific information, I have a flash movie that has typing. The movie is actually an educational activity for students (as young as kindergarder). When the page loads, it gives audio instructions ("type the word that you see"), and has a word like "CAT". They then retype the word in a box below the word CAT. This needs focus immediately when the page loads. Having any intermediate steps would only complicate things for the kids.
In addition to this, I have functional buttons (re-say instructions, for example) that are seperate flash movies. For IE, whenever these buttons are clicked I have them sending focus back to the main flash movie, that way if they were typing, they could keep typing after clicking the button. It may sound strange, but it is very comfortable, and extremely uncomfortable to have to re-click to give focus back. For the functional buttons (flash movies) I use the code:
<object onFocus="document.getElementById('FLASHID').focus();" ... .... >
Using onCLick would work just the same (and neither will work in Firefox).
Any ideas?
- jqp
- Posts: 5070
- Joined: November 17th, 2004, 10:56 am
- Location: In a box
- Contact:
So did this work, or not?
If it doesn't, what does the javascript console say?
If it doesn't, what does the javascript console say?
Code: Select all
<body onLoad="document.getElementById("FLASHID").focus();">
-
- Posts: 9
- Joined: February 19th, 2005, 5:54 pm
Console will say:
document.getElementById("FLASHID").focus is not a function.
This is what I mentioned in my first post. Further analysis shows that all methods/functions on the flash component (focus, click, blur, etc) do not work.
So no, this will not work.
I really appreciate the responses and effort on this from everyone. Please keep going!
document.getElementById("FLASHID").focus is not a function.
This is what I mentioned in my first post. Further analysis shows that all methods/functions on the flash component (focus, click, blur, etc) do not work.
So no, this will not work.
I really appreciate the responses and effort on this from everyone. Please keep going!
-
- Posts: 3451
- Joined: November 30th, 2002, 12:30 pm
You do have this, correct?Seeing your full code would probably help.
Code: Select all
<object id="FLASHID">
-
- Posts: 9
- Joined: February 19th, 2005, 5:54 pm
There are no syntax issues. Remember that it works in IE (and yes, I know IE often makes 'poorly' coded things work), but you'll have to trust me that it isn't a syntax issue. I've gone to great lengths to analyze & test this. You could reproduce it by simply using the above mentioned body tag, and adding a flash component with the same ID to the HTML page.
You can even try putting an onFocus="" in the <object> component - this will let you know when focus is given.
Having these 2 things is sufficient to reproduce & effectively fix the issue.
You can even try putting an onFocus="" in the <object> component - this will let you know when focus is given.
Having these 2 things is sufficient to reproduce & effectively fix the issue.
-
- Posts: 9
- Joined: February 19th, 2005, 5:54 pm
OK OK.. here's the exact HTML to reproduce:
Code: Select all
<html>
<body onLoad="document.getElementById('FLASHID').focus();">
<OBJECT ID='FLASHID' TYPE="application/x-shockwave-flash" WIDTH="640" HEIGHT="480" ALIGN="" data="test1.swf">
<PARAM NAME=movie VALUE="test1.swf">
</OBJECT>
</body>
</html>
- jqp
- Posts: 5070
- Joined: November 17th, 2004, 10:56 am
- Location: In a box
- Contact:
Okay, the code makes sense. I am curious if it works with EMBED instead of OBJECT (though OBJECT is obviously more proper, since it's the standard)
There's probably a workaround for this. I'll play with this later if I get a chance. It may not be until evening.
It may even involve FSCommands or something.
You also may needIt'll take some trial and error.
Just so I get it: There's an Input Text field within the Flash movie that needs to be focused when the page loads. The OBJECT must get the browser focus, and then Flash movie will give focus to the input. Right?
There's probably a workaround for this. I'll play with this later if I get a chance. It may not be until evening.
It may even involve FSCommands or something.
You also may need
Code: Select all
<param name="allowScriptAcess" value="true">
Just so I get it: There's an Input Text field within the Flash movie that needs to be focused when the page loads. The OBJECT must get the browser focus, and then Flash movie will give focus to the input. Right?
-
- Posts: 9
- Joined: February 19th, 2005, 5:54 pm
You've got it exactly.
I, myself, thought the same things about the <object> and <embed>. I have tried both, and thats why I used both tags in my initial posts - cuz I figured some people might ask about using <embed>.
I just now tried the "allowScriptAccess" param, which sadly did not work, but thanks for the suggestion.
When trying with the <embed> I tried the swLiveConnect just for the heck of it (it didn't work of course).
You may be right about the FScommand, but I haven't yet thought of a solution using it. If that is the way to go, then that's fine with me.
I had also thought about trying to simulate a mouse click on a Point that is overtop of the flash movie, but I'm doubtful Firefox would allow a simulated click due to security issues (and yes, if you're just now thinking it, I have tried <body onLoad="document.getElementById('FLASHID').click();"> ).
I, myself, thought the same things about the <object> and <embed>. I have tried both, and thats why I used both tags in my initial posts - cuz I figured some people might ask about using <embed>.
I just now tried the "allowScriptAccess" param, which sadly did not work, but thanks for the suggestion.
When trying with the <embed> I tried the swLiveConnect just for the heck of it (it didn't work of course).
You may be right about the FScommand, but I haven't yet thought of a solution using it. If that is the way to go, then that's fine with me.
I had also thought about trying to simulate a mouse click on a Point that is overtop of the flash movie, but I'm doubtful Firefox would allow a simulated click due to security issues (and yes, if you're just now thinking it, I have tried <body onLoad="document.getElementById('FLASHID').click();"> ).
- jqp
- Posts: 5070
- Joined: November 17th, 2004, 10:56 am
- Location: In a box
- Contact:
- jqp
- Posts: 5070
- Joined: November 17th, 2004, 10:56 am
- Location: In a box
- Contact:
-
- Posts: 9
- Joined: February 19th, 2005, 5:54 pm
I have used FSCommands. I'm not sure how they'd help though...
If I understand, you suggest using the flash FSCommand (from within the flash movie) to call JavaScript on the page, which tries to focus the flash movie? I believe this will result in the exact same thing.
What about going at this from another point of view. Instead of trying to focus the flash component, what if we capture the key presses in browser, and send them to the flash movie... Does anyone know how to programatically send a key press to a component? For example, if you had a page with forms & text inputs, sending key presses to different text fields that you decide without those text inputs having to be focused (no, not a value= type thing).
It really would be helpful if someone that actually works on the mozilla browser & knows some of its functionality and how it was programmed could help... Don't make me download the code and become an example of the benefits of open source .
If I understand, you suggest using the flash FSCommand (from within the flash movie) to call JavaScript on the page, which tries to focus the flash movie? I believe this will result in the exact same thing.
What about going at this from another point of view. Instead of trying to focus the flash component, what if we capture the key presses in browser, and send them to the flash movie... Does anyone know how to programatically send a key press to a component? For example, if you had a page with forms & text inputs, sending key presses to different text fields that you decide without those text inputs having to be focused (no, not a value= type thing).
It really would be helpful if someone that actually works on the mozilla browser & knows some of its functionality and how it was programmed could help... Don't make me download the code and become an example of the benefits of open source .
- jqp
- Posts: 5070
- Joined: November 17th, 2004, 10:56 am
- Location: In a box
- Contact:
either way, you're still dealing with the scriptability of the plugin, and Flash's scriptability is called FS Commands. You're half right at what I meant. I didn't mean having Flash call javascript and then javascript call a function Flash. I just meant having JavaScript call a function in Flash and skipping the first part.
-
- Posts: 1
- Joined: March 16th, 2005, 2:12 am
Got any luck?
I have problems with it too.
I've searched on macromedia's site, but got nothing for mozilla or firefox.
http://www.macromedia.com/cfusion/knowl ... ode=simple
I wonder why does mozilla (and firefox) have no focus method implementation of <embed>?
More over: there is no embed tag in HTML 4.01 or DOM specification!!! 8-0
I have problems with it too.
I've searched on macromedia's site, but got nothing for mozilla or firefox.
http://www.macromedia.com/cfusion/knowl ... ode=simple
I wonder why does mozilla (and firefox) have no focus method implementation of <embed>?
More over: there is no embed tag in HTML 4.01 or DOM specification!!! 8-0