ForumsProgramming Forum[Need help] hittest only works once?

60 13507
Voidcrystal
offline
Voidcrystal
138 posts
Nomad

when i make thise script:

onEnterFrame = function(){
if(ss.hitTest(_root.c2)){
_root.ss._x = -49.4;
}
}

it only does go to cords -49.4 once! the next time it happens nothing, can you solve it abn :P? Or anyone else??

  • 60 Replies
Voidcrystal
offline
Voidcrystal
138 posts
Nomad

btw maybe it is easier to do it in a class, but how??

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

To make a class, right click on the movieclip in the library and check the box labelled "export for ActionScript" Then, create a new actionscript file and add the code:

Class (MovieClip Name Here) extends MovieClip
{
function onEnterFrame()
{
if(this.hitTest(_root.wall))
{
_x = -50;
}
}
}

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

could not load class :S (i made it correct)

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

Is it saved as the exact name as what you entered in the export for actionscript box? (it's case sensitive)
Did you save it in the same folder?
is the begining part where you have the movieclip's name spelled correctly? (it's also case sensitive)

Oh, whoops, and make class lowercase, sorry

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

sorry i ment:

ss folder\\ss.as: Line 1: Syntax error.
Class ss extends MovieClip

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

like I said, make class lowercase, sorry

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

what is that? o,o

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

omfg it was not that, you made a mistake in the script o.O!

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

you said "Class" instead of "class".

How to make a class with the moving of the char?
like this script:

tr();

function tr() {
speed = 0.2
muv = 0
friction = 0.99

}

onEnterFrame = function() {

if (Key.isDown(Key.RIGHT) or Key.isDown(68)) {
muv += speed;
}
if (Key.isDown(Key.LEFT) or Key.isDown(65)) {
muv -=speed;
}




ss._x += muv;
muv *= friction;
}

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

And I told you twice that I screwed it up and to make class lowercase.

Add "class (movieclip name) extends MovieClip{
//code
}

inside the code you have the same thing you already have, but take out the line "tr()" and change "function tr" to "function onLoad"

And if something doesn't work, change "onEnterFrame = function()" to "function onEnterFrame()" although what you have will probably work.

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

ss.as: Line 8: ActionScript 2.0 class scripts may only define class or interface constructs.
}

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

what is your code?
you have code inside the class frame besides creating variables..

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

function onLoad() {
speed = 0.5
muv = 0
friction = 0.99
}

function onEnterFrame() {

if (Key.isDown(Key.RIGHT) or Key.isDown(68)) {
muv += speed;
}
if (Key.isDown(Key.LEFT) or Key.isDown(65)) {
muv -=speed;
}




ss._x += muv; muv *= friction;
}

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

You need "class ss extends MovieClip{" before all of that, and an extra "}" at the end

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

And you don't need "ss._x" just use "_x"

Showing 31-45 of 60