dcsimg
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: simple, basic math, need help

  1. #1
    Senior Member
    Join Date
    Feb 2001
    Location
    .ee
    Posts
    102

    simple, basic math, need help

    I have a number variable that changes from 0 to 17, so the maximum is 17.
    I need to make a conversion so I could use it to control _xscale from 0 to 100

    this is very basic stuff... how can I do it?

  2. #2
    Junior Member
    Join Date
    Apr 2005
    Posts
    5
    you'll need your number (n) and multiply it by 1% of 17 which is .17 then you need to multiply .83*n and add it to your product. That will give you the percentage you are looking for.

    so the formula is
    myNum = 17;
    n = percentage;
    percentloaded = ((myNum/100)*n)+((1-(myNum/100))*n);

    also you could add another variable to hold your percentage and do this.

    myNum = 17;
    myPerNum = myNum/100;
    n = percentage;
    percentloaded = (myPerNum*n)+((1-myPerNum)*n);

    Both work after this edit sorry I didn't have flash to test it out when I wrote it.
    Last edited by junkyard5dawg; 04-20-2005 at 11:35 PM.

  3. #3
    Senior Member
    Join Date
    Feb 2001
    Location
    .ee
    Posts
    102
    many thanks! I will try this but couldn´t it be done more simply?

  4. #4
    Junior Member
    Join Date
    Apr 2005
    Posts
    5
    Yea ... Just realized there's a mistake in the code ... anyways ... I put together a small fla for you to look over and apply.

    If you just want to hardcode it ... I did it that way so you could build the percent scale with any number (i.e. 34 instead of 17 etc.) A more simple version with the hardcoded numbers would look like this.

    percentloaded = (.17*n)+(.83*n) where n = the current %. You still need n because the number will constantly change. This code isn't as good because you would have to change it in 2 places for it to work properly again if you changed your 17 to a 24 later.

    Take your time looking at it and you'll see it's not as complex as it may look.
    Attached Files Attached Files

  5. #5
    Senior Member
    Join Date
    Feb 2001
    Location
    .ee
    Posts
    102
    thanks but this is something else already... I just need to make numbers 0 to 17 to change _xscale from 0 to 100.

  6. #6
    Junior Member
    Join Date
    Apr 2005
    Posts
    5
    I understand ... I just created a simple example that can be applied any way you like. Just use the code within the onClipEvent(mouseMove) as a loop anywhere in your movie and it will work as long as n changes.

  7. #7
    President PhobiK's Avatar
    Join Date
    Jan 2005
    Location
    Guatemala
    Posts
    918
    easier:
    Code:
    scale = (myVar/17)*100;
    This is MC. His _parents sent him to stop() by the super market to buy some _root beer if he wanted to gotoAndPlay() with his friends at the park later.

    This is my Blog!... The gaming Process
    Please check out my site: Giddel Creations

  8. #8
    Senior Member
    Join Date
    Feb 2001
    Location
    .ee
    Posts
    102
    Originally posted by PhobiK
    easier:
    Code:
    scale = (myVar/17)*100;
    thanks!!!

  9. #9
    President PhobiK's Avatar
    Join Date
    Jan 2005
    Location
    Guatemala
    Posts
    918
    No problem .
    This is MC. His _parents sent him to stop() by the super market to buy some _root beer if he wanted to gotoAndPlay() with his friends at the park later.

    This is my Blog!... The gaming Process
    Please check out my site: Giddel Creations

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center