Maki
Maki

Reputation: 11

Flash CC Canvas get width/height of Object/Shape

im using Flash CC Canvas for a little Animation. And currently I am having a problem. I have a shape(rectangle) and a text-field ('this.text_box') on my stage. For that i get this code when publishing:

(function (lib, img, cjs) {

var p; // shortcut to reference prototypes

// library properties:
lib.properties = {
    width: 550,
    height: 400,
    fps: 24,
    color: "#FFFFFF",
    manifest: []
};

// symbols:

// stage content:
(lib.test2 = function() {
    this.initialize();

    // text_layer
    this.text_box = new cjs.Text("HELLO WORLD!", "italic 25px 'Pragmatica Bold'");
    this.text_box.name = "text_box";
    this.text_box.lineHeight = 27;
    this.text_box.lineWidth = 154;
    this.text_box.setTransform(197.5,173.1);

    // box_layer
    this.shape = new cjs.Shape();
    this.shape.graphics.f("#0066FF").s().p("AuSFPIAAqcIclAAIAAKcg");
    this.shape.setTransform(274.4,191.5);

    this.addChild(this.shape,this.text_box);
}).prototype = p = new cjs.Container();
p.nominalBounds = new cjs.Rectangle(457.9,358,183,85.8);

})(lib = lib||{}, images = images||{}, createjs = createjs||{});
var lib, images, createjs;

Now, how can i change the height and width of that rectangle? For Example when the text in the text-field ("Hello World") is longer, the rectangle is also getting bigger. Is that possible? Bec i tried but cant get/access the height/width of the rectangle, so do i have to redraw it? And hows that working?

Thanks in advance for help :) Greetz

Upvotes: 1

Views: 1451

Answers (1)

Bryan Wienczkowski
Bryan Wienczkowski

Reputation: 46

From within Flash CC for canvas output, to get the width and height of a movieClip (someMC) is this:

this.someMC.nominalBounds.width
this.someMC.nominalBounds.height

actually if you traced out this:
console.log(this.someMC.nominalBounds);

This will spit out an array for that object with all sorts of properties that you have access to.

Hope that helps,

B

Upvotes: 1

Related Questions