-
[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!!!
-
-
Busy doing nothing
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!
-
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 !!!
-
Busy doing nothing
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!
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|