A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] What do i have to change in this code to use it within on/onClipEvent handler ???

  1. #1
    Banned
    Join Date
    Mar 2007
    Location
    Albania , prishtina
    Posts
    274

    [RESOLVED] What do i have to change in this code to use it within on/onClipEvent handler ???

    I have a code that i use in MC but i want to add it the hitTest ... because of that i need to change all the code to use it within on/onClipEvent handler ??

    Here is the code::

    Code:
    if(!_root.Player.hitTest(_root.Water)){
    on(keyPress "<Left>"){
    	this._x -= 2;
    	Sword = "Left";
    }
    on(keyPress "<Right>"){
    	this._x += 2;
    	Sword = "Right";
    }
    on(keyPress "<Up>"){
    	this._y -= 2;
    	Sword = "Up";
    }
    on(keyPress "<Down>"){
    	this._y += 2;
    	Sword = "Down";
    }
    
    on(keyPress "<Space>"){
    	if(Sword == "Left"){
    		_root.Player.SwordL.gotoAndPlay(2);
    	}else if(Sword == "Right"){
    		_root.Player.SwordR.gotoAndPlay(2);
    	}else if(Sword == "Up"){
    		_root.Player.SwordU.gotoAndPlay(2);
    	}else if(Sword == "Down"){
    		_root.Player.SwordD.gotoAndPlay(2);
    	}
    }
    }
    And that code that i use on(keyPress"<Space>"){ } , can it be simplier ??

    Thanks!!!

  2. #2
    Banned
    Join Date
    Mar 2007
    Location
    Albania , prishtina
    Posts
    274
    *bump*

  3. #3
    Busy doing nothing Boris the Frog's Avatar
    Join Date
    Jan 2001
    Location
    Derby, UK
    Posts
    305
    as for your space check
    1. you could change the if statements to a switch statement
    or as I can see that you are using the first character of "Right" ie R for _root.Player.SwordR.gotoAndPlay(2)
    I would look at extracting the first char of whatever 'Sword' is equal to (ie. get the 'R') and use that to tell the correct mc where to go
    Code:
    on(keyPress "<Space>"){
    switch (Sword){
    case "Left":
    case "Right":
    case "Up":
    case "Down":
    _root.Player["Sword" + Sword.charAt(0)].gotoAndPlay(2);
    }
    --------------------------------------------------
    ‘There is no emoticon to express how I am feeling’ - Comic Book Guy
    There's an effective, simple solution to carbon sequestration... it's called 'coal', so leave it alone!
    There's an effective, simple solution to carbon capture....it's called 'trees', so plant some!

  4. #4
    Banned
    Join Date
    Mar 2007
    Location
    Albania , prishtina
    Posts
    274
    Thanks and where can i use that code , If Player is not touching Water he can walk ... If he is touching the water the code will not work ???

    I dont know how to do that !!!

  5. #5
    Busy doing nothing Boris the Frog's Avatar
    Join Date
    Jan 2001
    Location
    Derby, UK
    Posts
    305
    you need to use 'Key' in your actionscript with a listener added to it.
    Check out the flash help for key.addListener method for more info.

    This site has some examples on using it as well:
    http://flash-creations.com/notes/asclass_key.php
    --------------------------------------------------
    ‘There is no emoticon to express how I am feeling’ - Comic Book Guy
    There's an effective, simple solution to carbon sequestration... it's called 'coal', so leave it alone!
    There's an effective, simple solution to carbon capture....it's called 'trees', so plant some!

  6. #6
    Banned
    Join Date
    Mar 2007
    Location
    Albania , prishtina
    Posts
    274
    *bump*

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