A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: two mc on stage alter eachother

  1. #1
    Member
    Join Date
    Sep 2014
    Posts
    77

    two mc on stage alter eachother

    Hello,

    Two MovieClips on stage, the code in each one is the same as the following:

    onClipEvent (mouseDown) {
    //
    if (_currentframe == 1) {
    this.gotoAndStop(2);
    } else if (_currentframe == 2) {
    this.gotoAndStop(1);
    }
    //
    }

    But when either mc is clicked, the two mc(s) behave the same (either go to 2nd frame or back to 1st at the same time). Even when every mc was given an instance name e.g. mc1, mc2

    and the code change as the following;

    //for mc1
    onClipEvent (mouseDown) {
    //
    if (_root.mc1._currentframe == 1) {
    _root.mc1.gotoAndStop(2);
    } else if (_root.mc1._currentframe == 2) {
    _root.mc1.gotoAndStop(1);
    }
    //
    }

    //for mc2
    onClipEvent (mouseDown) {
    //
    if (_root.mc2._currentframe == 1) {
    _root.mc2.gotoAndStop(2);
    } else if (_root.mc2._currentframe == 2) {
    _root.mc2.gotoAndStop(1);
    }
    //
    }

    the problem still there. Any advice?

    Thanks!

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    That's because you are telling them both the same thing about each other, and I assume they are both on frame 1 at the beginning.

  3. #3
    Member
    Join Date
    Sep 2014
    Posts
    77
    Quote Originally Posted by fruitbeard View Post
    Hi,

    That's because you are telling them both the same thing about each other, and I assume they are both on frame 1 at the beginning.

    Hello,

    Even if each mc was put on different layer, off course, on the 1st frame, still affecting each other.

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    You would need to attach your *.fla and describe what it is you wish to happen as I am not on the same page with it.

  5. #5
    Member
    Join Date
    Sep 2014
    Posts
    77
    Thank you fruitbeard for your time trying to help, that's great of you!

    Problem solved!!!

    Here is the code:

    //With two movieClips(mc1, mc2) on stage(_root) on the 1st frame.
    //this code attached to the 1st frame on stage.
    _root.mc1.onRelease = clickMC;
    _root.mc2.onRelease = clickMC;
    //
    function clickMC() {
    trace("you clicked the "+this._name+" movie clip.");
    if (this._currentframe == 1) {
    this.gotoAndStop(2);
    } else if (this._currentframe == 2) {
    this.gotoAndStop(1);
    }
    }

    Regards!

  6. #6
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    You can also shorten that down slightly
    PHP Code:
    function clickMC()
    {
        
    trace("you clicked the " this._name " movie clip.");
        if (
    this._currentframe == 1)
        {
            
    this.gotoAndStop(2);
        }
        else
        {
            
    this.gotoAndStop(1);
        }

    I always knew that your onClipEvent (mouseDown) was never going to work the way you wanted it to.

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