ActiveDen

Flash math Problems !!!

132 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 1 and 9 items
  • United Kingdom
  • Referred between 1 and 9 users
smoke_e_joe says

Im having problems with flash working some math for me.

Im simply trying to get it to resize a box by useing setting passed from the xml. So im passing in a width which is called “hw” for holder width and “bw” for boarder width. so i have the holder width at 720 and the boarder width 20. im trying to add both these together to get the background to add 20 pixels width to it so it looks like this.

centre.grey._width = hw+bw;

no i have traced this and instead of getting “740” as you expect i get “72010” which is massive.

the funny thing is if i minus it i get “700” why wont it add it though? i have set “hw” and “bw” as number variables but still doesnt work.

If anyone can help be greatly appretiated. :)

3 years ago
279 posts
  • Has been a member for 4-5 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 1 and 9 items
  • Netherlands
  • Referred between 10 and 49 users
FonZ says

it won’t add as numbers, because flash thinks they are strings, so they get added as strings.

3 years ago
132 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 1 and 9 items
  • United Kingdom
  • Referred between 1 and 9 users
smoke_e_joe says

how come it will take it away though? and is there a way around this?

3 years ago
132 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 1 and 9 items
  • United Kingdom
  • Referred between 1 and 9 users
smoke_e_joe says

Think i’v sorted it. I have set the width to the holder and then used that to add the boarder to the background.

centre.grey._width = holder._width+bw;

always something simple! thanks fonz.

3 years ago
561 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 1 and 9 items
Marvidude says

this should also do it, if its AS2

centre.grey._width = parseInt(hw)+parseInt(bw);
3 years ago
132 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 1 and 9 items
  • United Kingdom
  • Referred between 1 and 9 users
smoke_e_joe says

Thanks Marvidude That works a treat as well much appreciated.

3 years ago
1234 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 50 000 and 100 000 dollars
  • Elite Author
  • Bought between 10 and 49 items
  • United States
  • Referred between 50 and 99 users
MBMedia says

The reason it would subract as you wanted but not add is because a String can’t be subracted, but it can be added. “Blue” + ” ” + “Green” will equal “Blue Green” and XML gives info as Strings, so “720” + “10” would make “72010”. So in order to do math on the numbers, it must be converted to numbers first, that’s what Marvidude’s method is doing with parseInt, Number() will also work. But since strings cannot be subracted, it automatically converted it to numbers when you tried to subract :)

3 years ago
722 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Netherlands
  • Referred between 50 and 99 users
BigZ says
var hw:Number = 720 
var bw:Number = 20
centre.grey._width = hw+bw

This should work too I guess…

3 years ago
4324 posts
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Tutorial to a Tuts+ Site
  • Contributed a Blog Post
  • Interviewed on the Envato Notes blog
  • Grew a moustache for the Envato Movember competition
  • Community Moderator
  • Beta Tester
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 10 and 49 items
  • United Kingdom
  • Referred between 1 and 9 users
Reaper-Media says
Or to really mess things up:
centre.grey._width = ((holder._width*1)+(bw*1))
:D:P

normally works for me…
3 years ago
Reaper-Media is a moderator
patrickjansendesign
patrickjansendesign Recent Posts
Threads Started
152 posts
  • Has been a member for 3-4 years
  • Sold between 1 000 and 5 000 dollars
  • Bought between 1 and 9 items
  • Brazil
  • Referred between 1 and 9 users
patrickjansendesign says

You can always hard-force to number;
centre.grey._width = Number(hw)+Number(bw);
It’s not pretty but gets the job done

3 years ago
by
by
by
by
by