Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Document width/height in ActionScript

Explorer ,
Jan 19, 2011 Jan 19, 2011

Hello,

I'm in the (sometimes frustrating) middle of the "porting scripts from JS to AS3" process. A couple of little findings to share.

I've found that what is a simple division of numbers in JS:

var myHeight = app.activeDocument.height;

var myWidth = app.activeDocument.width;

var ratio = myWidth/myHeight;

needs to be written in a slight different way in ActionScript3:

var myHeight:Number =  parseFloat(app.activeDocument.width.valueOf())

var myWidth:Number = parseFloat(app.activeDocument.height.valueOf());

var ratio:Number = myHeight/myWidth;

That's because, for some reason, it seems that app.activeDocument.width is not a String, like the API reference says.

Not a Number as I would have supposed, but an Object - at least this is what comes from the ExtensionBuilder code hinting:

Schermata 2011-01-19 a 23.01.01.png

and from the Problems tab in Flash Builder.

Is that... correct?!

So, in order to divide height and width, I have to parseFloat() their valueOf().

Now, since in one of the next steps I need to fill an app.activeDocument.resizeImage() method, the required parameters are:

width:Object

height:Object

resolution:Number

plus a resampleMethod

In my script I have to divide width and height by a scaling factor, then use them in the resizeImage() as Objects.

I can do this in two ways:

var scalingFactor:uint = 4:

var finalHeight:Object = myHeight/scalingFactor;         // myHeight and ratio

var finalWidth:Object = finalHeight.valueOf() / ratio;   // as calculated before

So the result of a division of a Number (myHeight) and a Uint (scalingFactor) can be automatically casted as an Object.

While an Object (finalHeight) can't be directly divided by a Uint, but its valueOf() yes, and the result is finally casted as an Object.

Having spent some extra time scratching my head with this, apparently, trivial porting of three JS code lines, I hope to be of some help to those approaching a similar problem.

Regards,

Davide

TOPICS
Actions and scripting
2.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Jan 20, 2011 Jan 20, 2011
LATEST

Try asking your question  in the actionscript forum http://forums.adobe.com/community/flash/flash_actionscript3

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines