Note that there are some explanatory texts on larger screens.

plurals
  1. PORGB gradient based on percentage of file loaded
    primarykey
    data
    text
    <p>I'm working on my first Flash project, and for my preloader I'd like to do a really simple gradient based on the percentage loaded. The preloader says "77% loaded...", where the number 77 is a dynamic text instance called percentLoaded. I'd like the textColor of percentLoaded to change on a gradient from #000000 to #FFFFFF, in gray-scale.</p> <p>Therefore, I can't simply do:</p> <pre><code>percentLoaded.textColor=(currentValue/100)*0xFFFFFF; </code></pre> <p>This just converts the textColor to a multiple of FFFFFF, but outputs a color since it's not three separate components. Currently, here's what I've got:</p> <pre><code>percentLoaded.text=currentValue.toString(); percentLoaded.textColor=rgb2hex((currentValue/100)*255, (currentValue/100)*255, (currentValue/100)*255); </code></pre> <p>Where "rgb2hex" is a function defined within the class as such:</p> <pre><code>public function rgb2hex(r:Number, g:Number, b:Number) { return '0x'+(r &lt;&lt; 16 | g &lt;&lt; 8 | b).toString(16).toUpperCase(); } </code></pre> <p>It doesn't look like this is actually changing the color of the font though. I've imported flash.text.TextField and flash.display.MovieClip, but am not sure if I'm missing something else. Would this be easier to do with string concatenation? Or is there maybe something going on with currentValue/100 and passing that as a Number?</p> <p>If curious, I found the code for rgb2hex <a href="http://www.ozzu.com/flash-forum/rgb-code-hex-conversion-code-need-speed-t21429.html" rel="noreferrer">here</a>.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload