Moving a movie clip via key press event question.

I have a project where I'm trying to move the movie clip: "wally", up and down three levels of a stage.
However, from the default position I have him move up 145 pixels, and down 120 pixels.
I want to limit this action to one use, meaning if wally goes up once from his default position he must come back down, and vice versa, if he goes down he must come back up(or stay on that level). Also, if he goes up the 145 pixels, he needs to come back down 145 pixels, likewise if he goes down 120 pixels, he needs to come back up 120 pixels. I might be over-thinking this, as I had to strip it back to the starting code the other day, and am at a loss once more. If this'd be easier performed by moving with keyboard arrows and case statments, let me know, as I'm stumped.
Starting code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressHandler1);
function keyPressHandler1(event:KeyboardEvent):void
          if(event.keyCode==38)
                    wally.y -= 145;
                    else if(event.keyCode==40)
                    wally.y += 120;

use:
wally.startY = wally.y;
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressHandler1);
function keyPressHandler1(event:KeyboardEvent):void
          if(event.keyCode==38)
if(wally.y==wally.startY){
                    wally.y -= 145;
} else if(wally.y>wally.startY){
wally.y=wally.startY
                    else if(event.keyCode==40)
if(wally.y==wally.startY){
                    wally.y += 120;
} else if(wally.y<wally.startY){
wally.y=wally.startY;
p.s. please mark helpful/correct responses.

Similar Messages

  • Question about generate key press event to system. help plz.

    I am wondering if it is possible to write a java program to generate key press event(not receiving)to the local system so all the other program in the system receive those key press event also. Thanks.

    Hi,
    :. I don't know what exactly you intend to accomplish. But, I have used the following code in order to simulate keys pressing inside a Java application.
          /* - - - Simulates TAB (java.awt.Event)
          EventQueue evtq = Toolkit.getDefaultToolkit().getSystemEventQueue();
          evtq.postEvent( new KeyEvent(this, KeyEvent.KEY_PRESSED,
                          0, 0, KeyEvent.VK_TAB, KeyEvent.CHAR_UNDEFINED) );
          evtq.postEvent( new KeyEvent(this, KeyEvent.KEY_RELEASED,
                          0, 0, KeyEvent.VK_TAB, KeyEvent.CHAR_UNDEFINED) );
          /* - - - Simulates Shift+TAB (java.awt.Event)
          evtq.postEvent( new KeyEvent(this, KeyEvent.KEY_PRESSED, 0,
                          InputEvent.SHIFT_DOWN_MASK, KeyEvent.VK_TAB,
                          KeyEvent.CHAR_UNDEFINED) );
          evtq.postEvent( new KeyEvent(this, KeyEvent.KEY_RELEASED, 0,
                          InputEvent.SHIFT_DOWN_MASK, KeyEvent.VK_TAB,
                          KeyEvent.CHAR_UNDEFINED) );:. However, as far as I know to send keys to the whole OS you have to create a 'Hook' as described inside Win32API documentation. That's for Microsoft Windows naturaly.
    Cheers.
    Roque

  • Unable to receive Tab key press event

    Hello,
    I have written a component which extends JComponent.
    For that , when Tab key is pressed I need to process something.
    I have overridden the function processKeyBinding in my class.
    But I am not getting any event for tab key press. For all the other key press events, the function is being called.
    I also tried to create a action and add it to the action map. But that is also not working.
    Can anyone explain me why it is not working and give me the solution.
    Thanks in advance,
    Anu

    public static void removeTabFromFocusTraverval(Component c) {
         int id = KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS;
         Set strokes = c.getFocusTraversalKeys(id);
         Set newStrokes = new HashSet(strokes);
         newStrokes.remove(KeyStroke.getKeyStroke("TAB"));
         c.setFocusTraversalKeys(id, newStrokes);
    }

  • How to binding a key press event of "Esc" to "cancle" button

    I create a class extended JComponent. Than I add a button named "cancle " to it.
    Than I add the class's instance to a JDialog object.
    I try to get the key press event through add a keyListener to the class instance, but no works.
    I try to add a keymap and action map to the dialog 's getRootPane() also no works.
    Who can tell me how can I do?

    Thats the way I did it:
        // map escape key
        ActionListener escapeActionListener = new ActionListener()
          public void actionPerformed(ActionEvent e)
            cancelPressed();
        this.registerKeyboardAction( escapeActionListener,
                                     KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false),
                                     JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );

  • Raise Key pressed event

    Hello, any know how can I raise a key press event throw code. For example I want to simulate that the user has press the A Key. How can I do that throw code?
    Thanks a lot !!

    Hi there,
    Your question has been discussed previously in the forums. Sounds like you want to programmatically click a button in WPF.
    Please check out this post
    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1329603&SiteID=1
    Thanks,
    Jennifer

  • How to detect space key pressed event

    I am working on a japplet where it is needed to pause the applet on the occurrence of a space bar key pressed event can anybody help
    thanks in advance

    Have a look at the tutorial:
    http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html
    http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html
    -Puce

  • How to handle form close event or escape key press event for user defined f

    Experts,
    Please let me know how to handle form close event or escape key press event for user defined form...
    Thanks & Regards,
    Pravin.

    Hi
    You can catch the form close event like this
    If ((pVal.FormType = 139 And (pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_CLOSE)) And (pVal.Before_Action = True)) Then
          Try
                   SBO_Application.SetStatusBarMessage(pVal.EventType.ToString())
          Catch ex As Exception
                    SBO_Application.SetStatusBarMessage(ex.Message)
            End Try
          End If
    Hope this helps
    Regards
    Arun

  • How to reach Combobox Items via Key pressed (Java5)

    Hallo all,
    I have a question. I have a JCombobox field and assume that it has its items like (Apple, Banana, Pear). How can I manage to jump into Pear item by pressing P in that combobox?

    I am sorry I was wrong. I had to tell that my Combobox value is in my Table and the CellListener doesn't allow to do that. If I am gonna have another Swing problem I am going to send my message to that forum. I don't want to duplicate this question right now. Here is my code.
        public void load() {
            serviceType = data.getMetadata(position).getMetadataValuesSorted().toArray(new MetadataValue[0]);
            String[] metadataValues = new String[serviceType.length];
            for (int i = 0; i < serviceType.length; i++) {
                MetadataValue values = serviceType;
    metadataValues[i] = values.getValue();
    final TableColumn col2 = table.getColumnModel().getColumn(1);
    col2.setCellEditor(new MetadataValueComboBoxEditor(serviceType));
    col2.setCellRenderer(new MetadataValueComboBoxRenderer(serviceType));
    public class MetadataValueComboBoxRenderer extends JComboBox implements TableCellRenderer {
    public MetadataValueComboBoxRenderer(final MetadataValue[] items) {
    super(items);
    final JComboBox newItems = new JComboBox(items);
    setRenderer(new DefaultListCellRenderer() {
    public Component getListCellRendererComponent(final JList list, Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
    if (value != null && value instanceof MetadataValue) {
    value = ((MetadataValue) value).getValue();
    final String valueString = (String)value;
    newItems.addKeyListener(new KeyAdapter() {
    public void keyTyped(KeyEvent e) {
    for (int i = 0; i < items.length; i++) {
    if (e.getKeyChar() == valueString.charAt(0)) {
    newItems.setSelectedItem(newItems.getComponent(i));
    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    registerComponent(this);
    public Component getTableCellRendererComponent(final JTable table, final Object value,
    final boolean isSelected, final boolean hasFocus, final int row, final int column) {
    if (isSelected) {
    setForeground(table.getSelectionForeground());
    super.setBackground(table.getSelectionBackground());
    } else {
    setForeground(table.getForeground());
    setBackground(table.getBackground());
    setSelectedItem(value);
    return this;
    public class MetadataValueComboBoxEditor extends DefaultCellEditor {
    public MetadataValueComboBoxEditor(final MetadataValue[] items) {
    super(new JComboBox(items));
    final JComboBox newItems = new JComboBox(items);
    registerComponent((JComponent) this.getComponent());
    ((JComboBox) getComponent()).setRenderer(new DefaultListCellRenderer() {
    public Component getListCellRendererComponent(final JList list, Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
    if (value != null && value instanceof MetadataValue) {
    value = ((MetadataValue) value).getValue();
    final String valueString = (String)value;
    newItems.addKeyListener(new KeyAdapter() {
    public void keyTyped(KeyEvent e) {
    for (int i = 0; i < items.length; i++) {
    if (e.getKeyChar() == valueString.charAt(0)) {
    newItems.setSelectedItem(newItems.getComponent(i));
    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    MetadataValueComboBoxEditor  and MetadataValueComboBoxRenderer inner classes doesn't allow me to select the item via key pressed.
    Edited by: NEO1976 on Mar 24, 2008 10:11 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Can we fire key press event programmatically????

    hi there,
    is it possible in java to fire a key press event (of the associated component) programmatically??? like we can fire action event of a button by saying
    button.doClick();
    thanks in advance.
    anshu

    You can do so by using awt.Robot.keyPress(), just don't forget to do awt.Robot.keyRelease() afterwards!
    Note that it doesn't work for Applets unless you sign them, for security reasons (you don't want to go into a site and have the applet click ctrl+alt+del for you, right?)
    Cheers!
    Moti

  • Moving three movie clips together to a y co-ordinate of an event click

    I have 9 buttons (with instance names mov_1 - mov_9) verticle along a page. I want movie clips a, b and c. with instance names (ltop, graphic and lbottom). to move in parrallel down the page to the y co-ordinates of each of the 9 button movie clips when clicked on. My code so far for each of the cases is:
      public function onClicked( e:MouseEvent ):void
       var circle:MovieClip = e.currentTarget as MovieClip;
       HtmlTextFieldFactory.formatTextFields(  [panel.title, panel.content], this.context );
       switch( circle )
        case mov_1:
         panel.title.htmlText = _modelDataHelper.getTextAssets( "ct1" );
         panel.content.htmlText = _modelDataHelper.getTextAssets( "c1" );
         panel.x = 30;
         panel.y = 438;
         circle.alpha = 1;
         circle.removeEventListener(MouseEvent.MOUSE_OUT, onMouseOut );
         circle.removeEventListener(MouseEvent.MOUSE_OVER, onMouseOver );
         var mov_1_y:Number = mov_1.y;
         var myTween1a:Tween = new Tween(graphic, "scaleY", Strong.easeOut, graphic.scaleY, 1, 2, true);
         var myTween1b:Tween = new Tween(graphic, "y", Strong.easeOut, graphic.y, mov_1_y, 2, true);
         var myTween1c:Tween = new Tween(ltop, "y", Strong.easeOut, ltop.y, graphic.y, 2, true);
         var myTween1d:Tween = new Tween(lbottom, "y", Strong.easeOut, lbottom.y, graphic.y + 135, 2, true);
         break;
    Currently on one click of mov_1, graphic moves to the correct place. But it takes a second click before ltop and lbottom move to the correct place. I am needing them to move at the same time, together.
    Any suggestions?
    Thanks

    This is happening because of what the value of graphic.y is at the time of instantiating myTween1c and myTween1d. Perhaps they should be this:
    var myTween1c:Tween = new Tween(ltop, "y", Strong.easeOut, ltop.y, mov_1_y, 2, true);
    var myTween1d:Tween = new Tween(lbottom, "y", Strong.easeOut, lbottom.y, mov_1_y + 135, 2, true);
    HTH

  • Move clips from timeline to event sub folder?

    Aloha,
    Is there a way to move clips in the timeline that I have cleaned into a sub folder in an event library?
    I come from a non FCP background and still trying to wrap my mind/workflow around the FCP formula.  Generally I clean clips and drop "some" into a "to be used later" folder. 
    Example - While on location I might shoot some location shots while im waiting around.  The locations shots will use in the last 3 mintues of a 25 minute finished project.  When I get to post I edit and clean all clips in the order they are received.  When I find the location clips I simply move them to a folder labled "to be used later".  When I get to the section of the project/timeline were the clips are needed I drag them or the entire folder into the timeline.  
    I see how to make a folder inside an event but I am not able to drag a clips from the timeline to this created folder.  I have tryied to hold down Shift, CMD, OPT, CTRL and have no sucess.
    Thanks you for your time and help.
    Frederick
    Marbelle

    Aloha Fox,
    Thanks for taking the time to answer my questions.  I feel you really understood my concern and gave me some good viable options.
    There is a lot for me to learn and unlearn. I have been editing for over 16 years and most of that time I was using Edius. This is big paradigm shift coming to the Mac and FCPX. 
    The idea for me is to edit the video and move the "to be used later clips" into a bin/folder instead of moving them to the location in the timeline were they will be used at that very moment.  Its just a preference, I know plenty folks would just move the clip to the location.  Edit software is just a tool I have to decide if FCPX is the right tool for me. 
    Thank you again Fox for your time and understanding of my question. 
    Be blessed,
    Frederick
    Marbelle

  • Key pressed event

    I need message to be displayed when certain key pressed. Why it's not working?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class TestKey extends JPanel implements KeyListener {
         public TestKey(){
              addKeyListener(this);
         public static void main(String arg[]){
               JFrame frame = new JFrame();
                  frame.setTitle("Test my keybord, man!");
                  frame.setSize(300, 200);
                  frame.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent e) {
                      System.exit(0);
                  Container contentPane = frame.getContentPane();
                  contentPane.add(new TestKey());
                  frame.setVisible(true);
         public void keyPressed(KeyEvent ke){
              System.out.println("key pressed");
         public void keyTyped(KeyEvent ke){
              System.out.println("key typed");
         public void keyReleased(KeyEvent ke){
              System.out.println("key released");
    }

      public TestKey(){
        setFocusable(true);//<----------
        addKeyListener(this);
      }

  • How to change a h:outputText value in the current form on key pressed event

    Hello Suners,
    Greetings! I'm developing my first JSF web application and i'm trying to figure a way out to change outputText value when key pressed on another inputText so that when the user is typing his name for example he can see the letters showing respectively in the outputText.
    I managed to do it onchange but the user must focus out of the inputText to see his name in the outputText which is not right and the form must submit onchange event which is annoying.
    <h:inputText value="#{login.username}" title="name" id="name" required="true" onchange="this.form.submit()" >
                                <f:validateLength maximum="10" minimum="1"/>
                                <f:validator validatorId="myValidator"/>
                                <f:valueChangeListener type="classes.MyListener"/>
    </h:inputText>Is there any listener i can associate with the "onkeypress" attribute? Can anyone help me to do that with JSF?
    King Regards,

    hi, with JSF 2 you got the ajax tag, just tried it and it works fine :)
    <h:inputText id="myinput" value="#{back.name}">
        <f:ajax execute="@this" event="keyup" render="outtext"/>
    </h:inputText>
    <h:outputText id="outtext" value="#{back.name}"/>or before JSF 2
    <h:outputScript name="jsf.js" library="javax.faces" target="head"/>
    <h:inputText id="myinput" value="#{back.name}" onkeyup="jsf.ajax.request(this, event, {render: 'outtext'}); return false;"/>
    <h:outputText id="outtext" value="#{back.name}"/>The name property is a simple String in the bean.
    Hope this helps
    Edited by: hereps on Aug 21, 2010 7:18 AM

  • Key Press Event

    I have been pouring through the TLF API docs looking for
    events to handle key presses on a TextFlow and I am not finding
    anything. I'm sure it's simple, can anyone give me a clue? I'm
    looking to detect Ctrl+B, Ctrl+I, etc.. to trigger formatting.

    The events go to the DisplayObjectContainerController. You
    will want to override the processKey event functions to add special
    handling. Those are in the protected methods section and are
    inherited from a base class.

  • Capture key press events with ExtendScript?

    Is it possible to do this?  I can't find an example in the documentation or online anywhere.  I'd really like to know when the user presses the arrow keys while viewing the slideshow in Bridge.
    Thanks!

    Thanks for the example Paul.  I can see how to listen to key down events on Windows and Dialogs that I create.  Do you know of way to listen for global (app-wide) key down events? These are not defined:
    app.addEventListener('keydown',...)
    app.document.addEventListener('keydown',...)
    I'm trying to add to the slideshow mode by having a little palette dialog with the context information shown that I need.  The default caption box doesn't have what our artists want.  If the palette window is in focus, I get the keydown event, but if they're using the arrow keys to flip through the slideshow, I can't capture those.
    Thanks for the help.

Maybe you are looking for