View Full Version : gotoAndPlay(x) doesn't work!!!
Hi
There're two MC in the scene named MC1 and MC2, I'm performing a hit test or droptarget while MC1 hits MC2, it should goes to frame2. However, it doesn't work. Why????????
Pls. help.
Many thx.
//Inside a MC1
on (rollOver) {
startDrag(this, true);
}
on (rollOut) {
stopDrag();
}
onClipEvent (enterFrame) {
//Drop target or hit test
if ((this._droptarget) == _root.MC2) {
gotoAndPlay(2);
//getURL works
getURL("http://www.yahoo.com")
}
//hit test
if(this.hitTest(_root.MC2)){
gotoAndPlay(2);
}
//moving MC
this._x += 5;
if (this._x>550) {
this._x = 1;
} else if (this._x<0) {
this._x = 550;
}
}
// End MC1
farafiro
11-27-2002, 08:31 AM
first, I just wanna ask does it ever stop drag ?? coz it won't ever rollOut as it starts dragging on the rollOver state??
yeh, it will roll out. The trick is that the MC is moving...
farafiro
11-27-2002, 08:42 AM
can u post the fla
how could i attach a fla file???
yeh, zipped. Here you are.
back to home now...will reply u on tomorrow.
Thanks
farafiro
11-27-2002, 09:02 AM
all u nee to do is to add _root before gotoAndPlay(2); , coz by adding the action to the MC you target its own time line not the _root, they have an independent time lines
Yeh, Yeh, Yeh, it works now....
>>coz by adding the action to the MC you target its own time line not the _root,
do you mean it targets the timeline inside itself (the MC)???
does droptarget perform the same?
Many many thanks
:D
farafiro
11-28-2002, 06:31 AM
NO, _dropTarget doesb't do the same, but it always return the absolute path, so u need an eval to do it, or to make it with flash 4 way likeif ((this._droptarget) == "/MC2") {
//....
}
//OR
if (eval(this._droptarget) == _root.MC2) {
//.......
}
what is eval??
i just started to learn actionscript by this month...
farafiro
11-28-2002, 07:17 AM
here it is from the MM dictionary
eval
Availability
Flash Player 5 or later for full functionality. You can use the eval function when exporting to Flash Player 4, but you must use slash notation, and can only access variables, not properties or objects.
Usage
eval(expression);
Parameters
expression A string containing the name of a variable, property, object, or movie clip to retrieve.
Returns
Nothing.
Description
Function; accesses variables, properties, objects, or movie clips by name. If the expression is a variable or a property, the value of the variable or property is returned. If the expression is an object or movie clip, a reference to the object or movie clip is returned. If the element named in the expression cannot be found, undefined is returned.
In Flash 4, the eval function was used to simulate arrays; in Flash 5, it is recommended that you use the Array object to simulate arrays.
You can also use the eval function to dynamically set and retrieve the value of a variable or instance name. However, you can also do this with the array access operator ([]).
Note: The ActionScript eval action is not the same as the JavaScript eval function, and cannot be used to evaluate statements.
Example
The following example uses the eval function to determine the value of the expressionpiece + x. Because the result is a variable name, piece3, the eval function returns the value of the variable and assigns it to y:
piece3 = "dangerous";
x = 3;
y = eval("piece" + x);
trace(y);
// Output: dangerous
OK thanks anyway.:p
>>coz by adding the action to the MC you target its own time line not the _root,
do you mean it targets the timeline inside itself (the MC)???
farafiro
11-28-2002, 07:33 AM
yes
if ((this._droptarget) == "/MC2") {
//....
}
if(this.hitTest(_root.MC2)){
//...
}
what's the difference??
farafiro
11-28-2002, 07:49 AM
they both will give you the same effect, but as I said before
_dropTarget was created for Flash 4, and hitTest for Flash 5+
also with hitTest(), u may make it very accurate by adding the _x and _y you want it to be hitted (like a spot)if(this.hitTest(_root.MC2._x,_root.MC2._y,tru e)){
//...
}
could you further help on this??
it sometimes hang after the question1 - the tick appers but it don't go to question2. why???
and the clock run faster and faster after each "play again"????
????
any logical errors????
farafiro
11-28-2002, 08:02 AM
worked very well here, but u might give it a time before hiding the tick and moving to the other question, too fast
but why do it sometimes hang???
i.e. _root.nextframe() don't work or what's wrong???
and the clock run faster and faster????
farafiro
11-28-2002, 08:09 AM
for the colck, yes for that when u hit play again u should clear the old interval, or it will conflict itnto the old one (each 1000 millisecond) and a new one
so put this "clearInterval(id);" in frame 7
for the nextFrame(), I donno but try to use gotoAndSPlay(2), I think nextFrame, makes the play head stops in the next frame
for the clock, it works.
for the gotoAndPlay(), i use it before.
but why i changed to nextframe() is because those blank frame is used for the time interval for showing the tick.
otherwise, if i use gotoAndPlay(), the tick will no longer appear.
and i find hard to programme the tick say appear for 2 seconds....
any easier way??
setTime((_root.tick._visible=true),2000) //doesn't work........
farafiro
11-28-2002, 08:22 AM
just expand those blank frames a little (if 12 fps, so 2 seconds = 24 frame)
farafiro
11-28-2002, 08:22 AM
just expand those blank frames a little (if 12 fps, so 2 seconds = 25 frame)
yeh,yeh,yeh,
expand the frame and use gotoAndPlay() works excellent.
btw, if i use startDrag() and stopDrag(), i can't get a empty cursor once i clicked on a word, am I right? any solutions other than my existing one?
Many many thanks.
farafiro
11-28-2002, 08:37 AM
sorry?? I don't get it :rolleyes: :confused:
per your msg
>>first, I just wanna ask does it ever stop drag ?? coz it won't ever rollOut as it starts dragging on the rollOver state??
if i use
on(press){
startDrag(this,true)
}
on(release){
stopDrag()
}
i can't get a empty cursor once i clicked on a word, am I right? any solutions?
farafiro
11-28-2002, 08:53 AM
I don't get what is empty cursor means but the code u wrote, basicly when u press the mouse u start drag this as long as u still pressing, and it stops it when releasing the object
empty cursor means ---
when i use
on(press) {
startDrag(this,true);
}
on(release) {
stopDrag();
}
i mean i can't release the object properly, the cursor is still attached with the obj until i click on another obj. It means the cursor is always attaching a obj once i click on any obj. anything suggestion?
it works fine now! but only in the MC not button. why??
one more question - how could i add a sound when performing the hittest? something like...
_root.onEnterFrame = function() {
if (_root.answer_am.hitTest(_root.question_am)) {
_root.answer_am._visible = false;
_root.tick._visible = true;
_root.score =1;
// how could i load and associate the sound
// from the library panel?????????
mysound = new Sound();
mysound.play();
_root.gotoAndPlay(2);
}
};
farafiro
12-01-2002, 06:37 AM
to attach a sound, first you should linkage it from the library. Chose it> right click> Linkage> Export tab, give it a name, thensong = new Sound
song.attachSound("the linkage name")
song.start(0,999)
many thanks.
....why do you change your name??
farafiro
12-02-2002, 05:38 AM
sorry?? chamge my name :confused: :confused:
are you called farafiro before?:confused:
anyway, are you the one in that photo? or is it your son?
thanks for your ans.
farafiro
12-03-2002, 06:08 AM
heheheeeeeeeeeeeeee
yes, I'm always farafiro
the pic is for my daughter
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.