A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: CS4-AS2-Can a MovieClip see its own name?

  1. #1
    Member
    Join Date
    Jan 2008
    Posts
    37

    CS4-AS2-Can a MovieClip see its own name?

    Well I want a movieclip to stop movie if it touches another movieclip that is in an Array, only problem is this movie Clip is also included in this movieclip.

    Code:
    ex. 
    //in First Frame//
    array = [_root.thing1, _root.thing2, _root.thing3]
    
    //inside thing1//
    for (i=0;i<_root.array;++i){
    if (this.hitTest (_root.array[i])){
    stop();}}

    Edit:

    So I was messing around with this to try and figure out what was wrong and I found that the Original monster can detect all its clones, and all its clones can detect the original, but the clones cant detect eachother.

    This is how I make clones of Thing
    Code:
    onClipEvent (load) {
    	ad = 1;
    }
    //in another MovieClip i have it add +1 to _root.thingnum every 2 secs to make them spawn for me//
    onClipEvent (enterFrame) {
    	if (_root.thingnum>ad) {
    		duplicateMovieClip("_root.thing", "thing"+ad, ad);
    		if (ad>1000) {
    			ad = 1;
    		} else {
    			ad++;
    		}
    	}
    }
    Does the Detection error have something to do with cloning? or What exactly am I doing wrong?

    so Ya main Questions:

    1. Is Cloning stopping Scripts?
    2. Am I calling the Collision Detection correctly?
    3. Can MovieClips see their Own Name?
    4. Am I going crazy from lack of sleep?
    Last edited by Degraiver; 12-30-2009 at 06:18 PM. Reason: New info was gathered.

  2. #2
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    if(clipFromArray._name != this._name){
    Z¡µµ¥ D££

    Soup In A Box

  3. #3
    Member
    Join Date
    Jan 2008
    Posts
    37
    Thanks. This Helps kinda. With this the original wont generate unnecessary scripts, but the duplicates still cant detect these codes for some reason.

  4. #4
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    Instead of using duplicateMovieClip, I tend to find that attachMovie works a lot better.
    Z¡µµ¥ D££

    Soup In A Box

  5. #5
    Member
    Join Date
    Jan 2008
    Posts
    37
    Hmm Ive been trying to work with this attachMovie thing, but it doesnt seem to be working....
    PHP Code:
    mob.attachMovie("mob1","mob"+ad,ad,this); 
    Thats how its suppose to be setup right?
    idname = mob1
    newname = mob+New integer
    depth = New integer
    initObj = This for the codes inside the original object

    Did i miss something? or misunderstand something?

  6. #6
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    make sure you have the linkage name of the clip you want to attach set to "mob1"
    Z¡µµ¥ D££

    Soup In A Box

  7. #7
    Member
    Join Date
    Jan 2008
    Posts
    37
    Awesome. I got it to add with attachMovie, but it has no script. Do I make a external script for it? Or how can I just copy the current script of the original into the copy. cause ive used _root.mob, mob, "mob", and "_root.mob" and they just dont do anything.

  8. #8
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    say your original has an instance name of "orig" and you have written an onClipEvent(enterFrame) function for it.

    You can say this:
    Code:
    var mc = attachMovie("mob1", "mob"+ad, ad, this);
    mc.onEnterFrame=orig.onEnterFrame();
    you can set any property using "mc.XXXX". For example:
    Code:
    //set any values or variables that you would set in
    //the original movieclip's onClipEvent(load) function.
    mc._x=10; //sets the starting x
    mc._y=50; //sets the starting y
    mc.xmov=12; //creates and sets a variable called "xmov"
    mc.ymov=14; //creates and sets a variable called "ymov"
    //if you want to define a variable without giving it a value,
    //just use:    mc.blah = undefined;
    
    mc.onEnterFrame=function(){
    //each frame increment x and y by xmov and ymov
    _x+=xmov;
    _y+=ymov;
    }
    That's just an example of setting properties. you can set whatever properties you need.

    Hope that helps!

    -Zippy Dee
    Z¡µµ¥ D££

    Soup In A Box

  9. #9
    Member
    Join Date
    Jan 2008
    Posts
    37
    attachMovie got way too complicated for me so i went back to duplicateMovieClip and I actually got it to work, the problem was
    PHP Code:
    (_root.mobList[i].hitTest(this)) 
    was wrong and i switched it to
    PHP Code:
    (this.hitTest(_root.mobList[i])) 
    it runs now but now something interesting is happening, I hope i can explain this well enough.

    The oldest object will stop when touched by the newest object but the newest will continue moving until touched by a newer object.

    so Obj1 still stop if touched by Obj2+ and Obj2 will stop if touched by Obj3+, so on and so forth. But I want it the other way around where Obj2 will stop if it touches Obj1 and Obj3 will stop if it touches Obj2-

    This is my current script
    PHP Code:
    for (i=0i<_root.mobList.lengthi++) {
                    if (
    this.hitTest(_root.mobList[i])) {
                        if (
    this._name == _root.mobListB[i]) {
                            
    spd 0.3;
                        } else {
                            
    spd 0;
                        }
                    }
                } 
    I was thinking i could just [i-1] or [i+1] but that doesnt work and nor does ([i]-1)..... an suggestions?

    Sorry about all this jumping around with the coding. Im just more comfortable with duplicateMovieClip than attachMovie.

  10. #10
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    maybe try setting this.spd and mobList[i].spd to 0:

    spd=0;
    _root.mobList[i].spd=0;

    And what is _root.mobListB?
    Z¡µµ¥ D££

    Soup In A Box

  11. #11
    Member
    Join Date
    Jan 2008
    Posts
    37
    well _root.mobList is _level0.mob1 which of course you know is the root command, but to check the name of the mob I cant use the same list so I had it creat a second list that only has the name mob1 w/o the _level0. If that makes any sense.

    the _root.mobList[i].spd=0; does nothing to any of the mobs in the list.

    I'd send you my game for you to look at but I'm not sure if you can understand my coding style... its not very elegent or neat LOL.

  12. #12
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    okay, let me take a look at the code then.
    Z¡µµ¥ D££

    Soup In A Box

  13. #13
    Member
    Join Date
    Jan 2008
    Posts
    37
    ok... I dont know what you wanted to look at so Im placing mob, and the Duplicater.

    Well here is the Mob's scripting. Its the object being duplicated.

    Some of the vars arent being used, but I havent taken them out yet.
    PHP Code:
    onClipEvent (load) {
        
    numb _root.port.ad;
        
    game 0;
        
    atkplyr false;
        
    mbatk false;
        
    dstnc 0;
        
    strgth 5;
        
    spd 0.3;
        
    atked false;
        
    lifehp 100;
        
    run;
        
    falling;
        
    hit;
        
    gravity 0;
        
    power 0;
        
    touch 0;
        
    hght 0;
        
    frend _root.mobList;
    }
    onClipEvent (enterFrame) {
        
    dstnc this._x-_root.player._x;

        
    hght _root.player._y-this._y;
        if (
    dstnc<=60 && dstnc>=10 && hght>=-50 && hght<=49) {
            
    spd 0;
            if (
    mbatk == false) {
                
    this.slash.gotoAndPlay(2);
                
    mbatk true;
            }
        } else {
            if (
    this.hitTest(_root.dntmve)) {
                
    spd 0;
            } else {
                for (
    i=0i<_root.mobList.lengthi++) {
                    if (
    this.hitTest(_root.mobList[i])) {
                        if (
    this._name == _root.mobListB[i]) {
                            
    spd 0.3;
                        } else {
                            
    this.mobList[i].spd 0;
                        }
                    }
                }
            }
        }
        if (
    this.slash._currentframe == 1) {
            
    mbatk false;
        }
        
    this.hp.hpbar._xscale Math.round(100*lifehp/100);
        if (
    lifehp<0) {
            
    lifehp 0;
        }
        if (
    lifehp<=0) {
            
    _root.player.exp += 1;
            
    duplicateMovieClip("_root.mny""mny"+_root.kpr_root.kpr);
            
    _root["mny"+_root.kpr]._x this._x;
            
    _root["mny"+_root.kpr]._y this._y;
            
    _root.kpr += 1;
            
    this.removeMovieClip();
        }
        if (
    _root.spring.hitTest(this._xthis._ytrue)) {
            
    power 10;
        }
        if (
    this.slash.atkzone.hitTest(_root.player.hitzone)) {
            if (
    atkplyr == false) {
                
    _root.player.hlth -= strgth;
                
    atkplyr true;
            }
        } else {
            
    atkplyr false;
        }
        if (
    this.hitspot.hitTest(_root.player.attack1)) {
            if (
    atked == false) {
                if (
    _root.player.attack1._currentframe>90) {
                    
    this._x += 15;
                }
                
    lifehp -= 50;
            } else {
            }
            
    atked true;
        } else {
            
    atked false;
        }
        if (
    gravity>power) {
            
    falling true;
        } else {
            
    falling false;
        }
        if (
    run == true) {
            
    this._x -= spd;
        }
        
    this._y -= (power-gravity);
        if (
    _root.floor.hitTest(this._xthis._ytrue)) {
            
    run true;
            if (
    falling) {
                
    hit true;
                
    power 0;
                
    gravity 0;
            }
        } else {
            
    hit false;
        }
        if (
    hit == false) {
            
    gravity += .2;
        } else {
        }
        if (
    gravity>18) {
            
    gravity 18;
        }


    And this is Port, the thing Duping my Mob object.

    PHP Code:
    onClipEvent (load) {
        
    id 1;
        
    ad 1;
    }
    onClipEvent (enterFrame) {
        if (
    _root.mobnum>ad) {
            
    duplicateMovieClip("_root.mob""mob"+ad, (999-ad));
            
    _root.mobList[ad] = "_level0.mob"+ad;
            
    _root.mobListB[ad] = "mob"+ad;
            
    _root["mob"+ad]._x 483;
            
    _root["mob"+ad]._y 188;
            if (
    ad>1000) {
                
    ad 1;
            } else {
                
    ad++;
            }
        }


  14. #14
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    you put
    Code:
    this.mobList[i].spd = 0;
    instead of
    Code:
    this.spd = 0;
    _root.mobList[i].spd = 0;
    that may be the problem.
    Z¡µµ¥ D££

    Soup In A Box

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