A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: [F8] WTF onKeyPress with ActionScript 2.0?!?!

  1. #1
    DivaDivo
    Join Date
    Mar 2008
    Posts
    15

    [F8] WTF onKeyPress with ActionScript 2.0?!?!

    Ok I make a button and coded it with onRelease and keypress.

    The button works fine on its release, but the onKeyPress for <Enter> will not work. WTF?

    I've read rumors that onKeyPress coding doesnt work in actionscript 2.0. Is that true?

  2. #2
    [Horse Thief] gotoAndCrash's Avatar
    Join Date
    May 2007
    Location
    NW, USA
    Posts
    576
    onKeyPress may not, but onKeyDown sure does!

    Here's what I did:
    I made a circle on my stage & converted to a movie clip & gave it the Instance Name - circ
    Then I made a new layer & typed this code into frame 1 (on the main timeline) :
    Code:
    circ.onPress = function () {
    	this._xscale = 200;
    }
    
    var keyLis:Object = new Object();
    keyLis.onKeyDown = function () {
    	if (Key.getCode() == Key.SPACE) {
    		circ._xscale = 100;
    	}
    }
    Key.addListener(keyLis);
    So, clicking on it with the mouse will expand it's _xscale to 200%, & pressing SpaceBar will shrink it back to 100%. I used SpaceBar instead of Enter because when viewing in Flash's preview player "Enter" has other functions & wouldn't do what I wanted it to do, though if viewing in an HTML page "Enter" would be fine, so you can swap the word "SPACE" with the word "ENTER".
    1 Infinite Loop, Cupertino is a portal of Hell.

  3. #3
    DivaDivo
    Join Date
    Mar 2008
    Posts
    15
    Why the expanding and contracting?

    I'm sorry I'm pretty new to actionscript.

  4. #4
    [Horse Thief] gotoAndCrash's Avatar
    Join Date
    May 2007
    Location
    NW, USA
    Posts
    576
    No worries - you didn't specify what action the button performed, so I just chose one at random. In place of those _xscale actions, put whatever action you want to perform, for example :
    Code:
    circ.onPress = function () {
    	getURL('http://www.flashkit.com/');
    }
    
    var keyLis:Object = new Object();
    keyLis.onKeyDown = function () {
    	if (Key.getCode() == Key.SPACE) {
    		getURL('http://www.google.com/');
    	}
    }
    Key.addListener(keyLis);
    1 Infinite Loop, Cupertino is a portal of Hell.

  5. #5
    DivaDivo
    Join Date
    Mar 2008
    Posts
    15
    Oh geez! That makes so much sense!

    I probably would have been able to figure that out if my head wasn't stuck in my computer.

    Thank you very much

  6. #6
    [Horse Thief] gotoAndCrash's Avatar
    Join Date
    May 2007
    Location
    NW, USA
    Posts
    576
    Very welcome
    Head stuck in computer, eh? Do you need me to call an ambulance?
    :P
    1 Infinite Loop, Cupertino is a portal of Hell.

  7. #7
    DivaDivo
    Join Date
    Mar 2008
    Posts
    15
    No the end of the day is almost here.

    That should be the cure.

  8. #8
    DivaDivo
    Join Date
    Mar 2008
    Posts
    15
    Ok nevermind. The end is never coming.

    So I have a movie that that loads in one scene via netConnection. When I move to another scene in the movie the audio keeps playing.

    Should I use some sort of clipEvent to solve this?

  9. #9
    [Horse Thief] gotoAndCrash's Avatar
    Join Date
    May 2007
    Location
    NW, USA
    Posts
    576
    I heard long ago that Scenes were bad, so I never used them, & thus I don't have any experience with their nuances.
    stopAllSounds(); may work, but you could also close the netStream by using :
    yourStream.close();
    1 Infinite Loop, Cupertino is a portal of Hell.

  10. #10
    DivaDivo
    Join Date
    Mar 2008
    Posts
    15
    Scenes are bad. Terrible. You can correctly code for buttons and scene changes, and Flash just picks what scene it find suitable.

    I'm not quite savvy enough to put this whole movie in one scene. I'm working on it.

    Your replies are so speedy. Thanks so much.

  11. #11
    [Horse Thief] gotoAndCrash's Avatar
    Join Date
    May 2007
    Location
    NW, USA
    Posts
    576
    Did either of those options work for killing the sound?
    If you wanted to send me your .fla, I might be able to help you get it all into one scene.
    "Best Practices" says that code should be in a central location. Here's a quote I found a while back from Bill Perry of Macromedia:
    “I throw a flash movie away if I don’t find the actions layer. Instead, actions in this file have been written in bits in more than 20 places!”
    1 Infinite Loop, Cupertino is a portal of Hell.

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