IT Community - Software Programming, Web Development and Technical Support

Instances of the movieclips are disappearing

This is a discussion on Instances of the movieclips are disappearing within the Flash Actionscript Programming forums, part of the Web Development category; Here is the script. Attach Code onClipEvent (load) { i = 10; timer = 0; } onClipEvent (enterFrame) { if (timer>=27) { timer = 0; ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Flash Actionscript Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 02-07-2008, 06:48 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Instances of the movieclips are disappearing

Here is the script.

Attach Code

onClipEvent (load) {
i = 10;
timer = 0;
}
onClipEvent (enterFrame) {
if (timer>=27) {
timer = 0;
_root.bomba.duplicateMovieClip("bomba"+bombNum,bom bNum);
eval("_root.bomba"+bombNum)._x =Math.round(Math.random()*(590));
eval("_root.bomba"+bombNum)._y = 0;
if (bombNum == 900) {
bombNum = 0;
} else {
bombNum++;
}
trace(bombNum);
}
this._y += 10;
timer++;
if (this._x<10 || this._x>590 || this._y>550) {
this.removeMovieClip();
}
}

As you can see it creates a bomb at a random x position at the top of the movie. Then it has the bomb falling to the bottom at a speed of 10, then it removes it. As you can see it generates many of these at but thats where the problem is. When some of them get about half way down they just dissapear and I can't seem to find any reason why.
I really would appreciate if someone would take a look at this and see if they can find anything wrong.

Thanks for all the Help!!!
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-11-2008, 01:26 AM
aramesh aramesh is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 72
aramesh is on a distinguished road
Default Re: Instances of the movieclips are disappearing

Hi,
The only thing with its _y property changing is the movieclip to which that code is attached. and you're probably having a depth collision that's causing your movieclips to disappear.

Regards

A.Ramesh.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-11-2008, 09:19 PM
aramesh aramesh is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 72
aramesh is on a distinguished road
Default Re: Instances of the movieclips are disappearing

Hi,
Just curious. What happens when you trace bombNum?

Regards
A.Ramesh
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-12-2008, 06:19 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: Instances of the movieclips are disappearing

Hi,
Thanks For ur reply.

When I trace bombNum I get a weird sequence like 1,2,3,4,1,2,5,1,2,6,1,2.
So how would I go about fixing the depth collision problem? I am kindve confused because when I trace bombNum it doesnt even get close to 900 before resetting.
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-14-2008, 04:44 AM
aramesh aramesh is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 72
aramesh is on a distinguished road
Default Re: Instances of the movieclips are disappearing

Based on the script you showed, you shouldn't even get that. So you must be declaring and manipulating that variable some place else in your script in addition to your enterFrame function. Where else are you using this variable?

And in the script you posted, when you say, for example, this._y += 10; what do you believe 'this' is referring to?
Regards
A.Ramesh

Last edited by aramesh : 02-15-2008 at 01:55 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-15-2008, 01:53 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: Instances of the movieclips are disappearing

yep, bombNum has to be initialized somewhere (unless this is flash 6 or earlier) and it's being changed elsewhere, timer is doing nothing useful and you're definitely getting depth collisions with that sequence of bombNum.
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-15-2008, 06:20 AM
aramesh aramesh is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 72
aramesh is on a distinguished road
Smile Re: Instances of the movieclips are disappearing

Oh I see said the blind man... So you must have these onClipEvent functions assigned to your movieclip named 'bomba'. When you duplicate the clip, you duplicate these functions as well. So all the new clips are stepping all over each other by running the same functions at the same time until each clip is removed.

BTW, what version of Flash are you using?

Rather than do this duplication work in a clip event (at least of a clip that you are duplicating), why don't you place the script in the timeline where the clip resides. Then script each bomb so it takes care of itself. For example:

Attach Code

bomba._visible = 0;
bombNum = 0;
makeBombF();
makeBombi = setInterval(makeBombF,1000);
function makeBombF() {
_root.bomba.duplicateMovieClip("bomba"+bombNum,bom bNum);
_root["bomba"+bombNum]._x =Math.round(Math.random()*(580))+10;
_root["bomba"+bombNum]._y = 0;
_root["bomba"+bombNum].onEnterFrame = function() {
this._y += 10;
if (this._y>550) {
this.removeMovieClip();
}
}
bombNum++;
if (bombNum >= 900) {
bombNum = 0;
}
trace(bombNum);
}

Regards

A.Ramesh
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-19-2008, 06:45 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: Instances of the movieclips are disappearing

Before I got your response I finally took all the script from what you put in the bomb script and also the timer, then I attached it to the main character which there is only one instance of and it worked fine. Then I took all that script again and used the function that you put together. It worked fine also. Are both ways acceptable or is there a certain benefit to one over the other? Just so I get this straight in my head, the original way I tried was bad because it caused there to be a gazillion instances all repeatedly running a script to just do one thing and all I really needed was one script to do do all that work?


So for the (this.removeMovieClip) code when the bomb goes off screen would it be better for that to be attached to each and every instance of the bomb? If I understand this right, it would be better because unlike the create bomb function, if I had to check every bomb out there (lets say numbers 1 through 100) to see that if it went off the screen on every enterframe, that would require a lot more processing power. Correct?


Thanks for being helpful with all my probably stupid questions. I am just learning and I really appreciate all the time you have put in to help me.
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-21-2008, 09:47 PM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: Instances of the movieclips are disappearing

Sorry just one more question. When you say depth collision problems, do you mean that the bombs and the bullets are on the same depth? Because when I changed the bombNum repeating from 0-100 and the bulletNum from 101-200 it seemed to get rid of the disappearing bombs.
Thanks again,
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-21-2008, 10:32 PM
aramesh aramesh is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 72
aramesh is on a distinguished road
Default Re: Instances of the movieclips are disappearing

Hi,
There can only be, at most, one movieclip at any given depth. a depth collision occurs when you assign a 2nd movieclip to a depth that already contains a movieclip. when that happens the most recently assigned movieclip occupies that depth and the other movieclip is removed from existence.

Regards

A.Ramesh
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble getting movieclips to play at random aramesh Flash Actionscript Programming 5 02-19-2008 06:48 AM
Change Movieclips Variables-Parameters Jamaican444 Flash Actionscript Programming 0 01-29-2008 02:16 PM


All times are GMT -7. The time now is 09:22 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0