Groups | Blog | Home
all groups > flash actionscript > october 2004 >

flash actionscript : Problem with function


colombopablo
10/3/2004 6:03:49 PM
Kinda new to ActionScripting, but this should be simple for many of you (I
hope) :-)

I'd be great if someone gave me a hint on this:

I have an MC whose visibility depends on another two MC's colliding (say MC1
and MC2)
on the first frame on root, I have placed this function:

function setVisibility () {
if (_root.MC1.hitTest(_root.MC2)) {
_root.MC._visible = true;
} else {
_root.MC._visible = false;
}
}

on MC1 (the one that hits) I put:

on (press) {
startDrag(this, true);
}
on (release) {
stopDrag();
}
// call function:
onClipEvent (enterFrame) {
_root.setVisibility ();
}

this works fine...

****NOW, HERES THE PROBLEM:
Since I want to use this function in Many others MCs I need to give it a
parameter, which would be the name of any guven MC whose visibility gets turned
on or off:

Here's what I tried:
(on root:)
// note I put a parameter in the function called myMC:

function setVisibility (myMC) {
if (_root.MC1.hitTest(_root.MC2)) {
_root.myMC._visible = true;
} else {
_root.myMC._visible = false;
}
}

Then on on MC1 (the one that hits) I use the function and use the name of MC
as parameter:

on (press) {
startDrag(this, true);
}
on (release) {
stopDrag();
}
// call function:
onClipEvent (enterFrame) {
_root.setVisibility (MC);
}

but this won't work... I wonder if this has to do with using movie clips as
parameters...

Any help or ideas on this?



kglad
10/4/2004 12:12:52 AM
function setVisibility (myMC) {
if (_root.MC1.hitTest(_root.MC2)) {
myMC._visible = true;
} else {
myMC._visible = false;
}
}

onClipEvent (enterFrame) {
_root.setVisibility (_root.MC);
}
colombopablo
10/4/2004 1:18:19 PM
Great! I think I got the idea:

I need to specify a path for the referenced movie clip when I actually use it
right?..

I also tried another parameter for the function to be more flexible..:

function setVisibility (clipHit, myMC) {
if (clipHit.hitTest (_root.MC2)) {
myMC._visible = true;
} else {
myMC._visible = false;
}
}

and then:

onClipEvent (enterFrame) {
_root.setVisibility (_root.MC1, _root.MC);
}

worked like a charm, loving it!!

Thanks so much kglad!!!



kglad
10/4/2004 2:19:59 PM
AddThis Social Bookmark Button