Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createEmptyMovieClip overrides existing MovieClip with the same depth #1509

Closed
relrelb opened this issue Nov 6, 2020 · 2 comments
Closed

Comments

@relrelb
Copy link
Contributor

relrelb commented Nov 6, 2020

In Free Rider 2, the bike and player disappear when hit.
After digging into this, I think I found the root cause of the problem:

class vehicle {
    ...
    function vehicle() {
        this.mymc = _root.createEmptyMovieClip("vehiclemc", 3);
        ...
    }
    ...
}
class bmx extends vehicle {
    function bmx() {
        super();
        ...
    }
    ...
    function createRagDoll() {
        _root.gui.message("Ouch! [Press Enter]",16764108);
        ...
        _root.player = new splitBike(this,this.getStick());
    }
    ...
}
class ragdoll extends vehicle {
    function ragdoll(pStick, pmc) {
        super();
        this.mymc = pmc;
        ...
    }
    ...
}

At the beginning, a new bmx is created. When hit, bmx.createRagDoll is called, which in turn creates a new ragdoll (during the creation of a new splitBike).
Since both bmx and ragdoll inherit from vehicle, the call to _root.createEmptyMovieClip("vehiclemc", 3) occurs multiple times.
The second call removes the MovieClip of bmx, just because a new MovieClip is created with the same depth.
The removal happens in add_child_from_avm.

The inherent problem here is that MovieClips store their children in a BTreeMap indexed by their depth, so children with the same depth cannot co-exist.
I tried to convert the BTreeMap to a simple Vec, but it was just too much to rewrite.

@Herschel
Copy link
Member

Herschel commented Nov 6, 2020

Not sure what's going on in this specific case--I'll have to take a look--but in general creating a movie on an already occupied depth removes the previous clip. A simple example:

var mc = createEmptyMovieClip("mc", 0);
mc.lineStyle(3, 0);
mc.lineTo(100, 100);

// mc2 is placed on the same depth as mc, so mc is destroyed
var mc2 = createEmptyMovieClip("mc2", 0);
mc2.lineStyle(3, 0xff0000);
mc2.lineTo(100, 200);
// Only mc2 is visible

@Herschel
Copy link
Member

Herschel commented Nov 7, 2020

Seems like this is a case of the original reference mymc auto-updating to the newly created clip. The clip does indeed get replaced when it uses the same depth, but since it uses the same path _root.vehiclemc, the mymc reference automatically points to the new clip. You can see it work if you manually update the references at the end of splitBike:

     pBike.mymc = _root.vehiclemc;
      this.myRagdoll.mymc = _root.vehiclemc;

Closing in favor of #1513.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants