|
|
|
#1 |
|
Member
Join Date: Aug 2009
Posts: 87
|
JAVASCRIPT running flash button
Hi! I think im almost there. Please help me out. I need to complete a script to trigger a click event using keyboard shortcuts:
*myListener is the name of my button Code:
<script>
function searchKeyPress(e)
{
if (e.keyCode == 113)
{
document.getElementById('myListener').click();
}
}
</script>
or Code:
<script language=javascript type="text/javascript" >
function ClickMe() {document.getElementById("myListener").click();}
</script>
How would javascript determine that this Id name, myListener, is inside a flash file? |
|
|
|
|
|
#2 |
|
Super Moderator
Join Date: Aug 2000
Location: Montréal
Posts: 13,242
|
I don't see what your JS function is supposed to do. Also, the element and its ID need to be in the DOM, like a div for instance; certainly not a button instance name inside an embeded swf. A JS function, like AS, can accept parameters, though. So if you need to pass a variable value, insert it in your JS.
if you HAVE to use javascript, use ExternalInterface.call to call the JS from flash. If not, this will suffice in Flash alone. Use a dyn txtfield with instance name keynum. Since you'll need to test the swf in standalone. The Function keys in authoring or test mode being reserved : PHP Code:
__________________
![]() AS 2.0 Forum Guidelines || Use PHP tags for code samples || Flash9 LiveDocs || AS 2.0 Language reference (CS4) |
|
|
|
|
|
#3 |
|
Member
Join Date: Aug 2009
Posts: 87
|
this will be inside flash right?
What I want to do is allow javascript to trigger the flash button. I have a quiz like flash file but the textbox and questions are separated. They are in javascript. Then I have a Clue button in flash which will operate this: Code:
getURL("javascript:command('clue',1)","_self");
So if the client is typing in the textbox (focus is in html), he/she wont be able to press F2 and operate the flash button function. He/she needs to click on the swf interface first before he could press F2. The problem is not all clients know it. So we have to do something that even if the focus is in html, and the client presses F2, he/she would still be able to operate the Clue button.
|
|
|
|
|
|
#4 |
|
Super Moderator
Join Date: Aug 2000
Location: Montréal
Posts: 13,242
|
PHP Code:
Check the ExternalInterface Class in the liveDocs (link in my footer) for all communications between JS and Actionscript. Your first post was unclear to me. My 1st answer was on how to trigger something in Flash when a key is pressed. Obviously not what you need right now. gparis
__________________
![]() AS 2.0 Forum Guidelines || Use PHP tags for code samples || Flash9 LiveDocs || AS 2.0 Language reference (CS4) |
|
|
|
|
|
#5 |
|
Member
Join Date: Aug 2009
Posts: 87
|
yes, thank you. Is this externalinterface has something to do with AS3? bec i started creating the website in AS2..
|
|
|
|
|
|
#6 | |
|
Member
Join Date: Aug 2009
Posts: 87
|
anyone who could help me? Bec. I dont really have an idea how to start. Is it possible?
and can someone tell me what is the meaning of this.addEventListener(KeyboardEvent.KEY_UP,keyPres sed); in this code: Quote:
Or is it possible to setfocus on both flash file and html? I mean, F1, F2, F3 when clicked will set focus on flash and run Key.getCode() == 113 from flash but letters and arrow keys will function in textbox (html).. Last edited by ayusuits; 11-02-2009 at 04:43 AM. |
|
|
|
|
|
|
#7 | |
|
Super Moderator
Join Date: Aug 2000
Location: Montréal
Posts: 13,242
|
Quote:
gparis
__________________
![]() AS 2.0 Forum Guidelines || Use PHP tags for code samples || Flash9 LiveDocs || AS 2.0 Language reference (CS4) |
|
|
|
|
|
|
#8 | |
|
Member
Join Date: Aug 2009
Posts: 87
|
Quote:
Last edited by ayusuits; 11-02-2009 at 09:47 PM. |
|
|
|
|
|
|
#9 |
|
Super Moderator
Join Date: Aug 2000
Location: Montréal
Posts: 13,242
|
getURL("javascript:command('listen',2)","_self");
Nope. getURL won't work. ExternalInterface.call("listen(2)"); as long as you have a JS function called listen which takes a number, like 2, as parameter. gparis
__________________
![]() AS 2.0 Forum Guidelines || Use PHP tags for code samples || Flash9 LiveDocs || AS 2.0 Language reference (CS4) |
|
|
|
|
|
#10 |
|
Member
Join Date: Aug 2009
Posts: 87
|
so I changed it to:
Code:
import flash.external.ExternalInterface;
ExternalInterface.call("listen(2)");
myListener = new Object();
myListener.onKeyDown = function() {
if (Key.getCode() == 113) {
getURL("javascript:command('listen',2)","_self");
}
};
Key.addListener(myListener);
and then javascript will just have to call ExternalInterface.call("listen(2)"); to run the same script with the flash button? Is my understanding correct? |
|
|
|
|
|
#11 |
|
Super Moderator
Join Date: Aug 2000
Location: Montréal
Posts: 13,242
|
no. replace the getURL.
gparis
__________________
![]() AS 2.0 Forum Guidelines || Use PHP tags for code samples || Flash9 LiveDocs || AS 2.0 Language reference (CS4) |
|
|
|
|
|
#12 |
|
Member
Join Date: Aug 2009
Posts: 87
|
but the geturl calls the javascript.. that is the function of the button.
|
|
|
|
|
|
#13 |
|
Super Moderator
Join Date: Aug 2000
Location: Montréal
Posts: 13,242
|
That's what ExternalInterface does. Calling JS.
gparis
__________________
![]() AS 2.0 Forum Guidelines || Use PHP tags for code samples || Flash9 LiveDocs || AS 2.0 Language reference (CS4) |
|
|
|
|
|
#14 |
|
Member
Join Date: Aug 2009
Posts: 87
|
ah i got it. it's the other way to call javascript. thanks!
|
|
|
|
|
|
#15 |
|
Member
Join Date: Aug 2009
Posts: 87
|
did I miss something?
PHP Code:
myListener is the instance name of the flash button Last edited by ayusuits; 11-03-2009 at 09:53 PM. |
|
|
|
|
|
#16 |
|
Super Moderator
Join Date: Aug 2000
Location: Montréal
Posts: 13,242
|
post your javascripts, the functions listen and check, cause i have no idea what you're trying to make happen just by looking at your AS.
And the _self param is ok with getURL but has no place in a JS call. gparis
__________________
![]() AS 2.0 Forum Guidelines || Use PHP tags for code samples || Flash9 LiveDocs || AS 2.0 Language reference (CS4) |
|
|
|
|
|
#17 |
|
Member
Join Date: Aug 2009
Posts: 87
|
nevermind. i already got it. thanks gparis
Last edited by ayusuits; 11-04-2009 at 03:19 AM. |
|
|
|
|
|
#18 |
|
Member
Join Date: Aug 2009
Posts: 87
|
GetURL converting to External Internal
Hi! Ive this from gparis, but unfortunately, the programmer said, the code is not working/running
I have this, originally: Code:
getURL("javascript:command('clue',1)","_self");
Code:
ExternalInterface.call("clue(1)");
ExternalInterface.call("command(clue, 1)"); and how do I convert this: getURL("javascript:loadHistory(+1)","_self"); Help me please... thanks! |
|
|
|
|
|
#19 |
|
Super Moderator
Join Date: Aug 2000
Location: Montréal
Posts: 13,242
|
if js function clue has a parameter, and 1 is supposed to be it, the call is different:
("clue", "1") use commas to separate the functions and its params Main difference in the call syntax would be: getURL("javascript:function") ExternalInterface.call('function') now, i really think that you should read the documentation. gparis
__________________
![]() AS 2.0 Forum Guidelines || Use PHP tags for code samples || Flash9 LiveDocs || AS 2.0 Language reference (CS4) |
|
|
|
|
|
#20 |
|
Member
Join Date: Aug 2009
Posts: 87
|
I dont know how the programmer was doing it. I tried
ExternalInterface.call('command', listen); it didnt work. Ah this one works: ExternalInterface.call("command('listen')"); Thanks~ |
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|