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; ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| 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... |
| Sponsored Links |
| |||
| 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. |
| |||
| 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... |
| |||
| 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. |
| |||
| 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... |
| |||
| 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 |
| |||
| 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... |
| |||
| 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... |
| |||
| 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 |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |