A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: I can't stop for loop mc and I don't know why my mc always be at the top left corner.

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    7

    I can't stop for loop mc and I don't know why my mc always be at the top left corner.

    Hi all,
    I really in a frustrated mood. I tried to figure it out all day long to finished my game. I'm making a game which has 2 levels; 3 scenes. And I ran into 2 problems. First, I can't stop my MCs which I attach to make them looping with this code
    Code:
    for(i=1;i<=numTarget;i++){
        tar=_root.attachMovie("mcTarget","t"+i,i);
        tar._x=random(Stage.width);
        tar._y=-random(Stage.height);
        tar._xscale=random(50)+50;
        tar._yscale=tar._xscale;
        tar.onEnterFrame=targetRun;
    }
    
    function targetRun(){
        this._y+=spdTarget*(this._xscale/100);
        if(this._y>Stage.height){
            this._x=random(Stage.width);
            this._y=-this._height;
        }
    I found they come back again and again in that very first scene until I go to the second scene. I tried so many code and put them in so many place for all day now. What I want is to remove them after the time is up which I use the Interval code.

    What I've tried, for example:
    Code:
    tar=delete _root.attachMovie("mcTarget","t"+i,i);
        mcTarget.swapDepths(_root.getNextHighestDepth(0));
        mcTarget.removeMovieClip();
    _root.tar.swapDepths(_root.getNextHighestDepth());
        _root.tar.removeMovieClip();
    mcTarget._visible=false;
    _root.tar._visible=false; 
    tar._visible=false;
    I also creat a function to remove it like this:
    Code:
    rePlaytxt = 365;
    
    rePlay = function(){
    rePlaytxt--;
    if(rePlaytxt==0){
    	clearInterval(countBack);
    	this.onEnterFrame=removeTarget;
    	gotoAndPlay("intro",2);	
    	}
    }
    
    countBack = setInterval(rePlay,50);
    
    function removeTargets():Void{
    	for(i=1;i<=numTarget;i++){
    		delete this["t"+i].onEnterFrame; 
    		this["t"+i].removeClip();
    	}
    }
    still...didn't work! I tries even make a fake scene before the real first scene. :P But nothing.

    What can I do any more? Where am I missing? or Where should I put the code on?-- I put it right in the Interval code.

    ----------------------------------------
    And another issue...
    Have anyone ever got thing like this: when use removeMovieClip(); and however you tried these MCs( which is a bullet in my game and another is that looping mc) will just appear at the top left corner. How can you get rid of it???

    480832_494287900610245_1004766040_n.png



    Thank you so much if you guys can tell me or just answer on one of the two.
    (T-T")

    Pleaseee HELP!

  2. #2
    Registered User
    Join Date
    Jan 2013
    Posts
    7
    Hey!... the first problem have been resolved now. :} with some help from my internet friend. Still, the MC stuck on the top left of the screen is annoying. Anyone knows how to fixed it?

    This is the code that created MC and removed it after its amount = 0 :
    Code:
    function ballRun(){
        this._x+=this.spdX;
        this._y+=this.spdY;
        for(i=1;i<=numTarget;i++){
            tar=_root["t"+i];
            if(this.hitTest(tar)){
                if(tar._currentframe==1){
                    score2++;
                    txtScore2.text=score2;
                    tar.play();
                    this.removeMovieClip();
                }   
            }
        }
    }
    
    mcBall2.onPress=function(){
        isDrag=true;
        mcBall2.startDrag(false);
    }
    
    mcBall2.onRelease=mcBall2.onReleaseOutside=function(){
        isDrag=false;
        mcBall2.stopDrag();
        cur++;
        me=_root.attachMovie("mcBall2","b"+cur,cur);
        me._x=mcBall2._x;
        me._y=mcBall2._y;
        me.spdX=(cenX-mcBall2._x)/2;
        me.spdY=(cenY-mcBall2._y)/2;
        me.onEnterFrame=ballRun;
        
    Code:
    amB--;
        amBall.text=amB;
        if(amB<=0){
            me=delete _root.attachMovie("mcBall2","b"+cur,cur);
            mcBall2._visible=false;
    } } _root.onEnterFrame=function(){ if(!isDrag){ mcBall2.spring(cenX,cenY,myInertia,myK); } empGraphic.clear(); empGraphic.lineStyle(8,0xFF0000); empGraphic.moveTo(empL._x,empL._y); empGraphic.lineTo(mcBall2._x,mcBall2._y); empGraphic.lineTo(empR._x,empR._y);
    You can see that I use ...
    Code:
    amB--;
        amBall.text=amB;
        if(amB<=0){
            me=delete _root.attachMovie("mcBall2","b"+cur,cur);
            mcBall2._visible=false;
    to remove the bullet.(ball)
    but every time when it is removed from the screen then it will reappear on the top left of the screen.
    Itried so many ways, many codes. I tried changed the position of empthyGraphic(MC) it dosen't work too.

  3. #3
    Senior Wabbit
    Join Date
    Jul 2008
    Location
    Winchester, Uk
    Posts
    215
    When using the attachMovie function you want to use removeMovieClip.

    So.
    Actionscript Code:
    me=_root.attachMovie("mcBall2","b"+cur,cur); //Your current attachment type

    me=delete _root.attachMovie("mcBall2","b"+cur,cur); //Current remove code
    me=mcBall2.removeMovieClip();
    There is almost no reason to use the delete function in AS2.
    One case you may wish to use it, is if you wanted to completely remove an handler on the MC ie. an onPress.
    Though I could be wrong about that my knowledge of the delete function is minimal as I don't use it.

    If all is fine, remark as resolved.

    Trust my code, and not my english.

  4. #4
    Registered User
    Join Date
    Jan 2013
    Posts
    7
    Quote Originally Posted by Mr Wabbit View Post
    When using the attachMovie function you want to use removeMovieClip.

    So.
    Actionscript Code:
    me=_root.attachMovie("mcBall2","b"+cur,cur); //Your current attachment type

    ok... but if I don't use it, so what should I use?
    me=delete _root.attachMovie("mcBall2","b"+cur,cur); //Current remove code
    me=mcBall2.removeMovieClip();
    There is almost no reason to use the delete function in AS2.
    One case you may wish to use it, is if you wanted to completely remove an handler on the MC ie. an onPress.
    Though I could be wrong about that my knowledge of the delete function is minimal as I don't use it.

    If all is fine, remark as resolved.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center