Be a Supporter!

Why won't it work!!! (AS)

  • 488 Views
  • 16 Replies
New Topic Respond to this Topic
AwesomeRific
AwesomeRific
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Why won't it work!!! (AS) 2007-08-03 03:35:47 Reply

It's freking pissing me off! I've been trying to fix this code for 2 weeks! It has no erorrs but It won't play the MC!!! I made 3 movie clips, standing, walking, and attacking, I even gave the damn thing instance names! then I put all movie clips into one movie clip known as maincharacter, then stop command on all frames!! Here is the code:

onClipEvent (mouseMove) {
Xd = _root._xmouse-_X;
Yd = _root._ymouse-_Y;
radAngle = Math.atan2(Yd, Xd);
_rotation = int((radAngle*360/(2*Math.PI))+270);
updateAfterEvent();
}
onClipEvent (enterFrame) {
_root.standing = true;
if (Key.isDown(Key.UP)) {
_root.attacking = false;
_root.standing = false;
_root.maincharacter.gotoAndPlay(2);
_root.maincharacter.walk.play();
if (_rotation>180) {
_y -= (5*Math.cos(Math.PI/180*(_rotation)));
_x += (5*Math.sin(Math.PI/180*(_rotation)));
} else {
_y += (5*Math.cos(Math.PI/180*(_rotation)));
_x -= (5*Math.sin(Math.PI/180*(_rotation)));
}
}
if (Key.isDown(Key.DOWN)) {
_root.standing = false;
_root.attacking = false;
_root.maincharacter.gotoAndStop(2);
_root.maincharacter.walk.play();
if (_rotation>180) {
_y += (5*Math.cos(Math.PI/180*(_rotation)));
_x -= (5*Math.sin(Math.PI/180*(_rotation)));
} else {
_y -= (5*Math.cos(Math.PI/180*(_rotation)));
_x += (5*Math.sin(Math.PI/180*(_rotation)));
}
}
if (_root.standing == true && _root.attacking == false) {
_root.maincharacter.gotoAndStop(1);
_root.maincharacter.stand.play();
}
}
onClipEvent (mouseDown) {
_root.attacking = true;
_root.maincharacter.gotoAndPlay(3);
_root.maincharacter.attack.play();
}


BBS Signature
Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Why won't it work!!! (AS) 2007-08-03 03:56:24 Reply

onClipEvent (mouseMove) {
Xd = _root._xmouse-_x;
Yd = _root._ymouse-_y;
radAngle = Math.atan2(Yd, Xd);
_rotation = int((radAngle*360/(2*Math.PI))+270);
updateAfterEvent();
}
onClipEvent (enterFrame) {
_root.standing = true;
if (Key.isDown(Key.UP)) {
_root.attacking = false;
_root.standing = false;
_root.maincharacter.gotoAndPlay(2);
_root.maincharacter.walk.play();
if (_rotation>180) {
_y -= (5*Math.cos(Math.PI/180*(_rotation)));
_x += (5*Math.sin(Math.PI/180*(_rotation)));
} else {
_y += (5*Math.cos(Math.PI/180*(_rotation)));
_x -= (5*Math.sin(Math.PI/180*(_rotation)));
}
}
if (Key.isDown(Key.DOWN)) {
_root.standing = false;
_root.attacking = false;
_root.maincharacter.gotoAndStop(2);
_root.maincharacter.walk.play();
if (_rotation>180) {
_y += (5*Math.cos(Math.PI/180*(_rotation)));
_x -= (5*Math.sin(Math.PI/180*(_rotation)));
} else {
_y -= (5*Math.cos(Math.PI/180*(_rotation)));
_x += (5*Math.sin(Math.PI/180*(_rotation)));
}
}
if (_root.standing == true && _root.attacking == false) {
_root.maincharacter.gotoAndStop(1);
_root.maincharacter.stand.play();
}
}
onClipEvent (mouseDown) {
_root.attacking = true;
_root.maincharacter.gotoAndPlay(3);
_root.maincharacter.attack.play();
}


BBS Signature
AwesomeRific
AwesomeRific
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to Why won't it work!!! (AS) 2007-08-03 16:01:05 Reply

Did you even do anything?


BBS Signature
Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Why won't it work!!! (AS) 2007-08-03 16:08:05 Reply

I changed some _X and _Y's to _x and _y, the code seems long and stupid and I can't be arsed to look at your fla. I'm pretty much sure the problem is with the fla and not the code.


BBS Signature
AwesomeRific
AwesomeRific
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to Why won't it work!!! (AS) 2007-08-03 16:15:08 Reply

what can be wron with the fla?????????


BBS Signature
Deso
Deso
  • Member since: May. 8, 2006
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Why won't it work!!! (AS) 2007-08-03 16:23:05 Reply

onClipEvent (mouseMove) {
Xd = _root._xmouse-_X; <---- what _x and _y (small chars)?
Yd = _root._ymouse-_Y;
radAngle = Math.atan2(Yd, Xd);
_rotation = int((radAngle*360/(2*Math.PI))+270); <--- what do you want to rotate?
updateAfterEvent();
}

You have to say of which movieclip the variables are.
e.g.: mc._rotation = 90


Art is something individual, nobody should try to copy something exactly how it is. Just let it happen and it will be the most beautiful thing you've ever experienced.

BBS Signature
AwesomeRific
AwesomeRific
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to Why won't it work!!! (AS) 2007-08-03 16:28:03 Reply

At 8/3/07 04:23 PM, Deso wrote:
onClipEvent (mouseMove) {
Xd = _root._xmouse-_X; <---- what _x and _y (small chars)?
Yd = _root._ymouse-_Y;
radAngle = Math.atan2(Yd, Xd);
_rotation = int((radAngle*360/(2*Math.PI))+270); <--- what do you want to rotate?
updateAfterEvent();
}
You have to say of which movieclip the variables are.
e.g.: mc._rotation =

Now it doesn't rotate at all, see what I'm trying to do is make the character do a walking motion when you press the arrow key and attack when you click the mouse!


BBS Signature
Deso
Deso
  • Member since: May. 8, 2006
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Why won't it work!!! (AS) 2007-08-03 16:46:42 Reply

Now it doesn't rotate at all, see what I'm trying to do is make the character do a walking motion when you press the arrow key and attack when you click the mouse!

Whatever you have to set an object infront of those _rotation und _x, _y or nothing works or you use with(object){}.
If you do you can move the object towards the mouse, but the whole code is very weired.


Art is something individual, nobody should try to copy something exactly how it is. Just let it happen and it will be the most beautiful thing you've ever experienced.

BBS Signature
AwesomeRific
AwesomeRific
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to Why won't it work!!! (AS) 2007-08-03 16:48:27 Reply

At 8/3/07 04:46 PM, Deso wrote:
Now it doesn't rotate at all, see what I'm trying to do is make the character do a walking motion when you press the arrow key and attack when you click the mouse!
Whatever you have to set an object infront of those _rotation und _x, _y or nothing works or you use with(object){}.
If you do you can move the object towards the mouse, but the whole code is very weired.

No it rotates fine, and it stays in the standing position, that's the problem I want it to do the walking motion when you press up or down, then attack motion when you click!


BBS Signature
TomMalufe
TomMalufe
  • Member since: Aug. 11, 2006
  • Offline.
Forum Stats
Member
Level 06
Programmer
Response to Why won't it work!!! (AS) 2007-08-03 16:54:55 Reply

It's considered bad coding practice to put code directly on a MovieClip. But, since it works I guess I will deal with it and try and help.

let me start with this one:

onClipEvent (mouseMove) {
Xd = _root._xmouse-_X;
Yd = _root._ymouse-_Y;
radAngle = Math.atan2(Yd, Xd);
_rotation = int((radAngle*360/(2*Math.PI))+270);
updateAfterEvent();
}

I assume that this finds the change in mouse position, and then angles the movieclip to face the mouse.
You don't have to add any sort of mc._rotation because it implicitly sees this._rotation and I'm assuming that's what you want. That code should work fine, does it?

Next we have this:

onClipEvent (enterFrame) {
_root.standing = true;

if (Key.isDown(Key.UP)) {
_root.attacking = false;
_root.standing = false;
_root.maincharacter.gotoAndPlay(2);
_root.maincharacter.walk.play();
if (_rotation>180) {
_y -= (5*Math.cos(Math.PI/180*(_rotation)));
_x += (5*Math.sin(Math.PI/180*(_rotation)));
} else {
_y += (5*Math.cos(Math.PI/180*(_rotation)));
_x -= (5*Math.sin(Math.PI/180*(_rotation)));
}
}

if (Key.isDown(Key.DOWN)) {
_root.standing = false;
_root.attacking = false;
_root.maincharacter.gotoAndStop(2);
_root.maincharacter.walk.play();
if (_rotation>180) {
_y += (5*Math.cos(Math.PI/180*(_rotation)));
_x -= (5*Math.sin(Math.PI/180*(_rotation)));
} else {
_y -= (5*Math.cos(Math.PI/180*(_rotation)));
_x += (5*Math.sin(Math.PI/180*(_rotation)));
}
}

if (_root.standing == true && _root.attacking == false) {
_root.maincharacter.gotoAndStop(1);
_root.maincharacter.stand.play();
}
}

that looks like it should make your character move in the direction that he is faceing... If there is no walking animation I would say that has something to do with your "stop command on all frames!!"...

You know what... I recommend you ask for help at a site called ActionScript.org They have a huge community of programmers that love to help with this kind of stuff... me included, but I would need to see your .fla to tell you what is going wrong here. Everything in this code looks fine, but I don't know what happens on frame 2 when you call _root.maincharacter.gotoAndStop(2);


BBS Signature
AwesomeRific
AwesomeRific
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to Why won't it work!!! (AS) 2007-08-03 16:58:56 Reply

At 8/3/07 04:54 PM, TomMalufe wrote: It's considered bad coding practice to put code directly on a MovieClip. But, since it works I guess I will deal with it and try and help.


I assume that this finds the change in mouse position, and then angles the movieclip to face the mouse.
You don't have to add any sort of mc._rotation because it implicitly sees this._rotation and I'm assuming that's what you want. That code should work fine, does it?


that looks like it should make your character move in the direction that he is faceing... If there is no walking animation I would say that has something to do with your "stop command on all frames!!"...

You know what... I recommend you ask for help at a site called ActionScript.org They have a huge community of programmers that love to help with this kind of stuff... me included, but I would need to see your .fla to tell you what is going wrong here. Everything in this code looks fine, but I don't know what happens on frame 2 when you call _root.maincharacter.gotoAndStop(2);

Basically all 3 of them are movie clips inside this one movie clips labeled as "maincharacter" then all I did a stop all 3 frames, because that's pretty much what I've learned from many tutorials. It's pissing me off, I'll try that actionscript.org though.


BBS Signature
Deso
Deso
  • Member since: May. 8, 2006
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Why won't it work!!! (AS) 2007-08-03 17:01:37 Reply

It's considered bad coding practice to put code directly on a MovieClip.

That's why I said weired ^^, but those _x, _y at the beginning are still upcased.


Art is something individual, nobody should try to copy something exactly how it is. Just let it happen and it will be the most beautiful thing you've ever experienced.

BBS Signature
AwesomeRific
AwesomeRific
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to Why won't it work!!! (AS) 2007-08-03 18:03:47 Reply

83 reviews and 11 replies? RRGGGGGH :( AS.org isn't even looking at my thread!


BBS Signature
Deso
Deso
  • Member since: May. 8, 2006
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Why won't it work!!! (AS) 2007-08-03 18:25:11 Reply

Perhabs few replies because of your bad code. Seems like nobody can really help you, to make this code work.


Art is something individual, nobody should try to copy something exactly how it is. Just let it happen and it will be the most beautiful thing you've ever experienced.

BBS Signature
AwesomeRific
AwesomeRific
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to Why won't it work!!! (AS) 2007-08-03 18:34:36 Reply

At 8/3/07 06:25 PM, Deso wrote: Perhabs few replies because of your bad code. Seems like nobody can really help you, to make this code work.

D: What am I suppose to do! No one is going to give me a new code Uhhhhh DAMMIT!


BBS Signature
Deso
Deso
  • Member since: May. 8, 2006
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Why won't it work!!! (AS) 2007-08-03 21:29:08 Reply

D: What am I suppose to do! No one is going to give me a new code Uhhhhh DAMMIT!

You're code is totally desolated. Only with the fla help is possible.


Art is something individual, nobody should try to copy something exactly how it is. Just let it happen and it will be the most beautiful thing you've ever experienced.

BBS Signature
AwesomeRific
AwesomeRific
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to Why won't it work!!! (AS) 2007-08-03 22:07:52 Reply

At 8/3/07 09:29 PM, Deso wrote:
D: What am I suppose to do! No one is going to give me a new code Uhhhhh DAMMIT!
You're code is totally desolated. Only with the fla help is possible.

You can find the fla. @

http://www.actionscript.org/forums/showt hread.php3?t=143723


BBS Signature