WaveF
WaveF

Reputation: 11

How can I get the dynamic created movieclip size in createjs?

I've created a dynamic movieclip in flash canvas animation project(cc2015), but couldn't get the size, it just return null. Even I've enabled MultiframeBounds in publish setting, it still gets nothing.

PS: If there's a textfield in the slide, I can get the bounds of textfield, but not the whole size.

Code below:

var root = this;
root.name = "Root";

(function(){

    var maxMcNum = 4;
    var wrapper = new createjs.MovieClip();

    for(var i=1; i<=maxMcNum; i++){
        eval("var slide"+ i +"=new lib.mc"+ i +"()");
        eval("wrapper.addChild(slide"+ i +")");
        eval("slide"+ i +".y = "+ (i-1) +"*slide"+ i +".nominalBounds.height");
    }

    root.addChild(wrapper);

    stage.on("click", function(){
        //alert(wrapper.frameBounds[wrapper.currentFrame]);
        alert(wrapper.getBounds());
    });

})();

Upvotes: 1

Views: 966

Answers (2)

gskinner
gskinner

Reputation: 2488

This is an issue with how Flash exports single frame MovieClip symbols. It attempts to optimize the output by subclassing Container instead of MovieClip. As a result, it does not output frameBounds for the symbol, so instances fall back on trying to calculate their bounds at runtime. As Lanny mentioned, runtime bounds do not include vector graphics, so you are getting "null" unless you add other content (like a text box).

I've reported this issue to Adobe, but you can work around it for now by putting code on the first frame of your single frame MCs (ie. your slides). For example, just putting null; in the first frame actions will force Flash to export the symbol as a MovieClip, and include frameBounds.

Your wrapper (I'm not totally sure why you are using a MC instead of a Container here), will use run time bounds, but that should work fine, as it will query the child elements and return the aggregate transformed bounds they return.

Upvotes: 1

Lanny
Lanny

Reputation: 11294

Why is your code eval'd?

Nominal bounds is a special property that is calculated and injected by the Flash CC export. By default, nothing has nominal bounds, and EaselJS has no built-in way to calculate it. You can get bounds of Bitmap, Text, and Sprites (as well as containers that contain them), however Graphics can not be calculated.

The getBounds method does not look up the nominalBounds, but if you toggle "multiframe bounds" in the publish settings, getBounds will will get the frameBounds that are assigned by Flash CC during export.

Upvotes: 0

Related Questions