evity77
asked on
How do I remove movie clip and play movie clip in Flash 8?
How do I remove movie clip (movie12) and then ._visible = true for movie clip (item1 & item2) exactly after (movie12) finish animate?
if (item1.hitTest(item2)) {
this.attachMovie("movie12" , "movie12a" , 100, {_y:item1._y, _x:item1._x});
item1._visible = false;
item2._visible = false;
movie12.gotoAndPlay(2);
movie12.removeMovieClip();
}
if (item1.hitTest(item2)) {
this.attachMovie("movie12"
item1._visible = false;
item2._visible = false;
movie12.gotoAndPlay(2);
movie12.removeMovieClip();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you don't understand let me know
ASKER
Thank you so much! Brilliant!!
ASKER
How do I animate movie12 after item1 finished animate? I tried to change the code as below but it's not working. I already put
var finishedAnim:Function; at the first frame and finishedAnim(); at last frame of item1..
var finishedAnim:Function; at the first frame and finishedAnim(); at last frame of item1..
if (item1.hitTest(item2)) {
item1.finishedAnim = function(){
this.attachMovie("movie12", "movie12a" , 100, {_y:item1._y, _x:item1._x});
movie12a.finishedAnim = function(){
item1._visible = true;
item2._visible = true;
movie12.removeMovieClip();
}
item1._visible = false;
item2._visible = false;
movie12.gotoAndPlay(2);
}
}
I don't see where item1 starts animating, aren't you missing a step? for example:
if (item1.hitTest(item2)) {
item1.play();//////HERE
item1.finishedAnim = function(){
this.attachMovie("movie12" , "movie12a" , 100, {_y:item1._y, _x:item1._x});
movie12a.finishedAnim = function(){
item1._visible = true;
item2._visible = true;
movie12.removeMovieClip();
}
item1._visible = false;
item2._visible = false;
movie12.gotoAndPlay(2);
}
}
if (item1.hitTest(item2)) {
item1.play();//////HERE
item1.finishedAnim = function(){
this.attachMovie("movie12"
movie12a.finishedAnim = function(){
item1._visible = true;
item2._visible = true;
movie12.removeMovieClip();
}
item1._visible = false;
item2._visible = false;
movie12.gotoAndPlay(2);
}
}
ASKER
your previous code only work if item1 hit item2 - movie12 will be animate.. but while movie12 is running, then I drag item3 on screen, movie12 will start all over again. I try to make if item3 hit item4, movie34 will be animate and all other movie will stop. together i attached the file.
function checkTarget(ToucherDrag) {
if (ToucherDrag.hitTest(scene)) {
myMovie(["item"+Num].gotoAndPlay(5));
ToucherDrag.gotoAndPlay(5);
if (item1.hitTest(item2)) {
this.attachMovie("movie12", "movie12" , 100, {_y:item1._y, _x:item1._x});
movie12.finishedAnim = function(){
item1._visible = true;
item2._visible = true;
movie12.removeMovieClip();
}
movie13.removeMovieClip();
movie34.removeMovieClip();
item1._visible = false;
item2._visible = false;
movie12.gotoAndPlay(2);
}
else if (item1.hitTest(item3)){
movie12.removeMovieClip();
movie34.removeMovieClip();
this.attachMovie("movie13", "movie13" , 100, {_y:item1._y, _x:item1._x});
movie13.finishedAnim = function(){
item1._visible = true;
item3._visible = true;
movie13.removeMovieClip();
}
item1._visible = false;
item3._visible = false;
movie13.gotoAndPlay(2);
}
else if (item3.hitTest(item4)){
movie12.removeMovieClip();
movie13.removeMovieClip();
this.attachMovie("movie34", "movie34" , 100, {_y:item3._y, _x:item3._x});
movie34.finishedAnim = function(){
item3._visible = true;
item4._visible = true;
movie34.removeMovieClip();
}
item3._visible = false;
item4._visible = false;
movie34.gotoAndPlay(2);
}
}
else {
//feedback.text="Out";
}
}
instead of removing movie12 directly or any other, call the handler, so the code for the finishing animation works and it will remove itself anyway, but consistently:
movie12.finishedAnim();
or send it to the last frame:
movie12.gotoAndPlay(movie1 2.totalfra mes);
So whenever you drag other movies to the stage, the other playing movie will finish normally.
Also check your if else statements to make sure there is no missing condition, or maybe some condition overriding the one you are expecting. To do this, remove all else words, making the code with lots of sequencial if, not else if's. Then let me know if you find the problem
movie12.finishedAnim();
or send it to the last frame:
movie12.gotoAndPlay(movie1
So whenever you drag other movies to the stage, the other playing movie will finish normally.
Also check your if else statements to make sure there is no missing condition, or maybe some condition overriding the one you are expecting. To do this, remove all else words, making the code with lots of sequencial if, not else if's. Then let me know if you find the problem
ASKER
i'm sorry. I don't understand on how to use only movie12.finishedAnim();
i already remove else. but when item1 hit item2, movie12 will animate then item1 and item2 disappear from screen. but if i remain else if, after movie12 finished animate, item1 and item2 will be appear back on screen.
however, in both condition (with or without else if), when we drag other object on screen, the current movie (eg: item1 + item2 = movie12).. movie12 will start again.
when item1 and item2 appear back on screen, both objects will be on top/overlap each other. so we need to separate both object before we can drag other object. eg item3 and item4 hit = movie34 suppose movie34 will be animate. otherwise, if we did not separate item1 and item2.. instead of movie34.. movie12 will be animate.
i already remove else. but when item1 hit item2, movie12 will animate then item1 and item2 disappear from screen. but if i remain else if, after movie12 finished animate, item1 and item2 will be appear back on screen.
however, in both condition (with or without else if), when we drag other object on screen, the current movie (eg: item1 + item2 = movie12).. movie12 will start again.
when item1 and item2 appear back on screen, both objects will be on top/overlap each other. so we need to separate both object before we can drag other object. eg item3 and item4 hit = movie34 suppose movie34 will be animate. otherwise, if we did not separate item1 and item2.. instead of movie34.. movie12 will be animate.
function checkTarget(ToucherDrag) {
if (ToucherDrag.hitTest(scene)) {
myMovie(["item"+Num].gotoAndPlay(5));
ToucherDrag.gotoAndPlay(5);
if (item1.hitTest(item2)) {
this.attachMovie("movie12", "movie12a" , 100, {_y:item1._y, _x:item1._x});
movie12a.finishedAnim = function(){
item1._visible = true;
item2._visible = true;
//movie12.removeMovieClip();
}
item1._visible = false;
item2._visible = false;
movie12.gotoAndPlay(2);
}
else if (item1.hitTest(item3)){
this.attachMovie("movie13", "movie13a" , 100, {_y:item1._y, _x:item1._x});
movie13a.finishedAnim = function(){
item1._visible = true;
item3._visible = true;
//movie13.removeMovieClip();
}
item1._visible = false;
item3._visible = false;
movie13.gotoAndPlay(2);
}
else if (item3.hitTest(item4)){
this.attachMovie("movie34", "movie34a" , 100, {_y:item3._y, _x:item3._x});
movie34a.finishedAnim = function(){
item3._visible = true;
item4._visible = true;
//movie34.removeMovieClip();
}
item3._visible = false;
item4._visible = false;
movie34.gotoAndPlay(2);
}
}
else {
//feedback.text="Out";
}
}
If you can send source code I can look it better. But it could try saving the initial position of the items (item1,item2,item3,item4) so when you finish animating movies, you can send them back there. For example, let's say in the initialization function you put:
item1.xold = item1._x;
item1.yold = item1._y;
then in the hittest if:
if (item1.hitTest(item2)) {
this.attachMovie("movie12" , "movie12a" , 100, {_y:item1._y, _x:item1._x});
movie12a.finishedAnim = function(){
item1._visible = true;
item2._visible = true;
//movie12.removeMovieClip( );
}
item1._visible = false;
item1._x = item1.xold;
item1._y = item1._yold;?// THEN THE SAME OTHER ITEMS SO THEY ARE BACK TO THEIR INITIAL POSITION
item2._visible = false;
movie12.gotoAndPlay(2);
}
That way you prevent them from hitting again. Other way would be to set a flag on them.
item1.xold = item1._x;
item1.yold = item1._y;
then in the hittest if:
if (item1.hitTest(item2)) {
this.attachMovie("movie12"
movie12a.finishedAnim = function(){
item1._visible = true;
item2._visible = true;
//movie12.removeMovieClip(
}
item1._visible = false;
item1._x = item1.xold;
item1._y = item1._yold;?// THEN THE SAME OTHER ITEMS SO THEY ARE BACK TO THEIR INITIAL POSITION
item2._visible = false;
movie12.gotoAndPlay(2);
}
That way you prevent them from hitting again. Other way would be to set a flag on them.