1

I'm trying to center something on the stage using javascript inside an Adobe Animate CC canvas doc. Before in AS3 I would have accesses to the stage property. So I would be able to do something like this

trace(stage.width);

I tried the same in js, but doesn't seem to work.

console.log(stage.width);

Does anyone know if there is an equivalent to the stage property in create js?

icekomo
  • 9,328
  • 7
  • 31
  • 59

3 Answers3

3

In a canvas project, use stage.canvas.width

For example, if you have a clip named myClip, you can center it like this:

this.myClip.x = stage.canvas.width / 2;
1
container.x = (lib.properties["width"]/2);

container.y = (lib.properties["height"]/2);

you can set values to lib properties. example:

lib.properties["height"] = "800"; // change to whatever you want

You can check your main js files top lines. These lines affect the style of you main canvas tag(check with inspect element). Notice that stage.canvas.width/heigth values change with browser resizing but lib.properties not so much

check image --> using lib. properties instead of stage

Prid
  • 1,272
  • 16
  • 20
  • ⭐ THANK YOU! This is the only code that worked regardless of the canvas element being responsive or resizing. `stage.canvas.width` returned the correct values relative to the `` element's size, but even so the elements were never truly centered in-canvas. Turns out the intrinsic width and height of the FLA document doesn't change in-canvas, and despite the canvas element being resized, the elements within the canvas respect the intrinsic width and height -- which `lib.properties['width'] / ['height']` return. Thanks a million :) It's a shame documentation is so poor and hard to find. – Prid Jul 27 '21 at 18:54
0

I'm not sure how to change the size or position in the .js, In Adobe Animate cc 2015.2 you simply open the .fla file and go to "publish settings" and select "centre stage" + "make responsive". this obviously for the browser.

If you mean actually positioning the stage to centre inside Animate CC. You will find an icon next to the "zoom" (100%), just click that and it will centre your project. Image of the icon I am talking about.