Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-17-2012, 03:00 PM   #1
uldzus
Registered User
 
Join Date: Apr 2012
Posts: 1
Question [AS2] Hide Duplicated clips

I am working on one simpe game and have faced an absticle. I create movie clips with timer and I have to hide/delete them onClick or something like that. so theres the code I made so far -

var v_startLaiks:Number=10;
var v_ticktime:Number=1000;
1sek.=1000
f_countdown = function()
{
v_timer=v_timer-1;

dublicet();
if (v_timer==0)
{
clearInterval(v_Countdown);
timerStarted=false;
trace ("Game Over!");
//gotoAndStop(3);
}
}

if (timerStarted)
{
//trace ("Taimeris jau aktivs");
}
else
{
var timerStarted:Boolean=true;
//trace ("Taimeris palaists");
var v_timer:Number=v_startLaiks;

dublicet();
v_Countdown = setInterval(f_countdown, v_ticktime);
}
a=1;
dublicet=function(){
q=random(2)+1;
duplicateMovieClip("clip"+q, "clip"+q+"_"+a, a);
_root["clip"+q+"_"+a]._x = random(900)+40;
_root["clip"+q+"_"+a]._y = random(500)+35;
a++;
}
//for(i=1; i<=5; i++){
// dublicet();
//}

var atkritumi1 = new Array(clip1_1,clip1_2,clip1_3,clip1_4,clip1_5,clip 1_6);
for (v_i=0; v_i<a; v_i++){
atkritumi1[v_i].onRelease = function() {
//this._visible=false;
removeMovieClip(this);
};
}
var atkritumi2= new Array(clip2_1,clip2_2,clip2_3,clip2_4,clip2_5,clip 2_6);
for (v_i=0; v_i<a; v_i++){
atkritumi2[v_i].onRelease = function() {
//this._visible=false;
removeMovieClip(this);
};
}

So, is there any way to do this!?
uldzus is offline   Reply With Quote
Old 04-18-2012, 03:43 PM   #2
Noct
Toys in the Attic...
 
Noct's Avatar
 
Join Date: Oct 2006
Location: NY
Posts: 3,022
Default

Welcome aboard.

For starters, there's several errors in the code you're showing that would keep it from even compiling.

First:
ActionScript Code:
1sek.=1000
That wont work for two reasons. You cannot start a variable with a number, and you cannot include a period.

Next up is your array declares:
ActionScript Code:
var atkritumi1 = new Array(clip1_1, clip1_2, clip1_3, clip1_4, clip1_5, clip 1_6);
You have a space in the middl eof your last variable in both these arrays (clip 1_6, and clip 2_6) , this will also cause an error.

As far as removing it when clicked, you didn't explain what the issue you are having here is... Do they not remove, do they not click at all, etc?...

You can start out by tracing output in those functions to test them. Something to the effect of:
ActionScript Code:
var atkritumi1 = new Array(clip1_1, clip1_2, clip1_3, clip1_4, clip1_5, clip1_6); for (v_i=0; v_i<atkritumi1.length; v_i++) {     trace("atkritumi1[v_i]: "+atkritumi1[v_i]);     atkritumi1[v_i].onRelease = function() {         trace(this);         removeMovieClip(this);     }; }

Also, just for future reference, because it is infinately easier this way, duplicate, attach, and createMovie all have an output variable. You use that to dynamically make property changes to objects without needing the long-form string evaluation.

I'd also suggest using getNextHighest to set your depths, unless you specifically need them to be at those levels. (1-6) Otherwise you may end up overwriting your old stuff going forward. lastly on that one, I personally like to set a variable to store the scope of dynamically generated clips, just to be sure I'm pathing them correctly.

random is actually depreciated now as well, but it's not going to break anything.
Quote:
random(value:Number) : Number

Deprecated since Flash Player 5. This function was deprecated in favor of Math.random().
ActionScript Code:
var clipScope:MovieClip = this; function dublicet():Void {     var q:Number = random(2)+1;     var targMc:MovieClip = clipScope["clip"+q];     var dNum:Number = targMc._parent.getNextHighestDepth();     var newMc:MovieClip = duplicateMovieClip(targMc, targMc._name+"_"+dNum, dNum);     newMc._x = random(900)+40;     newMc._y = random(500)+35; }

Hope something here was helpfull... You just need to give us more info on the problem (or show us the fla) to get more specific solutions.
__________________
http://rwithers.com
Noct is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:51 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.