PDA

View Full Version : Explain actionscript please



Dhryn
April 24th, 2006, 03:46 PM
I found the following code in a tutorial:

if (_root.stage1.hitTest(getBounds(_root).xMax, _y, true)) {
_root.stage1._x += mySpeed;
}
if (_root.stage1.hitTest(getBounds(_root).xMin, _y, true)) {
_root.stage1._x -= mySpeed;
}
if (_root.stage1.hitTest(_x, getBounds(_root).yMax, true)) {
_root.stage1._y += mySpeed;
}
if (_root.stage1.hitTest(_x, getBounds(_root).yMin, true)) {
_root.stage1._y -= mySpeed;
}

and modified it to work for my file, but it didnt come with an explination for how it works, I am main confused by the getBounds part, can some please explain this code to me?

Joppe
April 24th, 2006, 03:57 PM
if (_root.stage1.hitTest(getBounds(_root).xMax, _y, true)) {
_root.stage1._x += mySpeed;
}
if (_root.stage1.hitTest(getBounds(_root).xMin, _y, true)) {
_root.stage1._x -= mySpeed;
}
if (_root.stage1.hitTest(_x, getBounds(_root).yMax, true)) {
_root.stage1._y += mySpeed;
}
if (_root.stage1.hitTest(_x, getBounds(_root).yMin, true)) {
_root.stage1._y -= mySpeed;
}




if (_root.stage1.hitTest(getBounds(_root).xMax, _y, true)) {
_root.stage1._x += mySpeed;
}

This is for xmax = the highest point of _x in your movieclip like right side
xmin is the lowest xpoint to the left.
the same is for ymax and ymin.
hope that clears something up :S

Dhryn
April 24th, 2006, 04:07 PM
so does:

if (_root.stage1.hitTest(getBounds(_root).xMax, _y, true)) {
_root.stage1._x += mySpeed;
}

mean the right side of the object with any value for y?
and I am guessing the true part means that it does hit.

Joppe
April 25th, 2006, 12:36 PM
um yeah that means the right side of the object. Actually i dont know so much about getBounds I think they are quite weird aswell. But if you know what each line does im sure you can use it =)