[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using keypress with an text input field

Posted on 2006-05-25
22
Medium Priority
?
469 Views
Last Modified: 2012-06-27
I am trying to make an interface where you can type something in an input text field and hit enter to open a link to an outside web page instead of clicking on the submit buttton.  How can I do this?

I am using Flash 8
0
Comment
Question by:blainehilton
  • 10
  • 8
  • 4
22 Comments
 
LVL 7

Expert Comment

by:Ramy_atef
ID: 16762146
Hi
on the text box write this code

on (keyDown) {
      if (Key.isDown(Key.ENTER)) {
            getURL("http://www.cnn.com");
      }
}
0
 
LVL 7

Expert Comment

by:Ramy_atef
ID: 16762172
if you want to make sure that the text box is not empty you can :

on (keyDown) {
      if (Key.isDown(Key.ENTER) && this.text) {
          getURL("http://www.cnn.com");
     }
}
0
 
LVL 1

Author Comment

by:blainehilton
ID: 16762323
I tried what was suggested and it gave me an error saying that mouse events can only be applied to buttons.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16762351
Hi,

add the following code on frame not on textField
----------
var myListner = new Object();
myListner.onKeyDown = function()
{
      if (Key.isDown(Key.ENTER))
      {
            trace("http://www.cnn.com");
      }
};
Key.addListener(myListner);
----------

Important, add above code on frame...

Rgds
Aneesh
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16762357
Sorry, I forgot to add getURL

here is the complete code again:
----------
var myListner = new Object();
myListner.onKeyDown = function()
{
      if (Key.isDown(Key.ENTER))
      {
            getURL("http://www.experts-exchange.com");
      }
};
Key.addListener(myListner);
----------------

add above code on frame

Rgds
Aneesh
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16762384
Here is the final code...

I assume that your input textField instance name is "myInput",
(change instance name with your input textField instance name)

following code will check that if focus is inputField thenonly it will open the url on <Enter> key press
-----------
var myListner = new Object();
myListner.onKeyDown = function()
{
      if (Key.isDown(Key.ENTER) && Selection.getFocus().indexOf("myInput") != -1)
      {
            getURL("http://www.experts-exchange.com");

      }
};
Key.addListener(myListner);
-----------

Rgds
Aneesh
0
 
LVL 7

Expert Comment

by:Ramy_atef
ID: 16762456
the code i wrote you have write it on the text Input.
just click on the text Input and click F9 to open the Actions panel and write the code ..
0
 
LVL 7

Expert Comment

by:Ramy_atef
ID: 16762479
I've made you an example ..
you can download it from

www.pylon-group.com/temp/textField.zip

Regards,
Ramy
0
 
LVL 1

Author Comment

by:blainehilton
ID: 16762482
When I click on the text input and click F9 the window where the script goes says "Current selection can not have actions applied to it".  What do I do?
0
 
LVL 1

Author Comment

by:blainehilton
ID: 16762491
This is for Flash 8 right?
0
 
LVL 7

Expert Comment

by:Ramy_atef
ID: 16762507
you have to use the textInput component not the ordinary text box

Open the file i sent you and you will understand :)

www.pylon-group.com/temp/textField.zip
0
 
LVL 1

Author Comment

by:blainehilton
ID: 16762571
Okay we were able to open the file and it does work.  However on ours we have the ordinary text box I believe.  Where do I find this textInput component?
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16762581
Hi,

here I have uploaded a working version which works on normal textField

download Link:
http://www.yousendit.com/transfer.php?action=download&ufid=01A79007516EDF2D


Rgds
Aneesh
0
 
LVL 7

Expert Comment

by:Ramy_atef
ID: 16762588
just Click Ctrl + F7 or from  Window > Components
it'll open the components window for you

or simple copy the one i sent you and past it in your movie .. :)
0
 
LVL 1

Author Comment

by:blainehilton
ID: 16762654
Okay thanks for working with me on this, however we still are having some problems.  It will come up now, but if the Enter key is held down for a sec or so it will keep opening up multiple windows.  How can I change it to only open 1 window?
0
 
LVL 7

Accepted Solution

by:
Ramy_atef earned 2000 total points
ID: 16762709
onClipEvent (load) {
      flag = true;
}

on (keyDown) {
      if (Key.isDown(Key.ENTER) && this.text && flag) {
            getURL("http://www.cnn.com");
            flag = false;
      }
}
0
 
LVL 7

Expert Comment

by:Ramy_atef
ID: 16762725
That will make the window opens only once if that what you want ..
I've just used a flag that i sent it to true as the component loads , and when the user click on the key, i check if the flag is ture ..if it is , then the window opens and after hat i sent it to false to prevent it from opening again
0
 
LVL 1

Author Comment

by:blainehilton
ID: 16762763
okay when we added that into the general frame actionscript area and run it there is an error that states "clip events are permitted only for moving clip instances).  I feel you are on the right track, but do not have the experience to know the answer.
0
 
LVL 1

Author Comment

by:blainehilton
ID: 16762787
okay, we may have got it to work here by commenting out the first and 3rd line so its just flag=true
0
 
LVL 7

Expert Comment

by:Ramy_atef
ID: 16762790
you select the component and write this code on it , replace the old code with this one ..
don't write the code on the key frame
0
 
LVL 7

Expert Comment

by:Ramy_atef
ID: 16762803
yes it's the old code i've just added

onClipEvent (load) {
     flag = true;
}

and added " && flag" it in the if statment

   if (Key.isDown(Key.ENTER) && this.text && flag) {


last thing

flag = false;

0
 
LVL 1

Author Comment

by:blainehilton
ID: 16763986
thanks!, we just used it your way the 2nd to last with the commenting of the other parts
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
Suggested Courses
Course of the Month17 days, 15 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question