Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay SVG gradients using Flash?
    primarykey
    data
    text
    <p>I'm using AS3 (Flash) to <strong>read SVG files</strong> and <strong>display</strong> them. The problem is correctly displaying a <strong>linear/radial gradient.</strong></p> <p>Following is an example of a simple <strong>linear gradient</strong> from <strong>Red</strong> to <strong>Blue</strong>, in SVG.</p> <pre><code>&lt;linearGradient id="GRADIENT_1" gradientUnits="userSpaceOnUse" x1="107.3938" y1="515.5684" x2="105.2488" y2="428.8614" gradientTransform="matrix(0.9988 0.0485 0.0485 -0.9988 0.8489 711.6634)"&gt; &lt;stop offset="0" style="stop-color:red"/&gt; &lt;stop offset="1" style="stop-color:blue"/&gt; &lt;/linearGradient&gt; </code></pre> <p>I've been able to read the <strong>colors</strong> from the gradient (stop's styles), and their <strong>spacing</strong> through the gradient (stop's offsets).</p> <p>Okay, so now I've got a <strong>nice gradient</strong> with the <strong>right colors</strong> and <strong>right amount of space</strong> between them, but with <strong>NO rotation or scale</strong>, and its <strong>off position!</strong>.</p> <p>The answer is to feed <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/geom/Matrix.html#createGradientBox()" rel="nofollow noreferrer">a <strong>Matrix</strong></a> into Flash's gradient function.</p> <hr> <h3>Method 1: Use the supplied matrix</h3> <p>The <strong><a href="http://www.w3.org/TR/SVG11/coords.html#TransformMatrixDefined" rel="nofollow noreferrer">Matrix supplied</a></strong> by SVG, <a href="http://www.w3.org/TR/SVG11/coords.html#TransformAttribute" rel="nofollow noreferrer"><strong>gradientTransform="matrix(a,b,c,d,e,f)"</strong></a> appears to be effectively useless since when you feed that <strong>matrix</strong> into Flash's <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Graphics.html#beginGradientFill()" rel="nofollow noreferrer"><strong>beginGradientFill() function</strong></a>, it displays the gradient <strong>stretched</strong> over the shape so much so only the center color of the gradient is visible, like a solid fill.</p> <hr> <h3>Method 2: Generate a Matrix using 2 gradient points</h3> <ul> <li>The <strong>x1, y1</strong> tags might be the point on screen where the <strong>gradient begins at.</strong></li> <li>The <strong>x2, y2</strong> tags, might be the point on screen where the <strong>gradient ends.</strong></li> </ul> <p>When I say "2 gradient points", I'm referring to x1,y1 and x2,y2, which are mostly telling you <strong>where on the shape</strong> does the <strong>gradient start &amp; end.</strong></p> <p>There's the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/geom/Matrix.html#createGradientBox()" rel="nofollow noreferrer"><strong>Matrix.createGradientBox()</strong> function</a> which creates a matrix for use with gradients, but the parameters are <strong>very different than what SVG</strong> gives me. It wants:</p> <ol> <li><strong>Width</strong> --- used the relative distance between the 2 gradient points here (X axis)</li> <li><strong>Height</strong> --- used the relative distance between the 2 gradient points here (Y axis), <em>but got incorrect results</em> --- also tried using the <strong>distance between the 2 gradient points</strong> here, but I didn't know what to fill into Width!</li> <li><strong>Rotation angle</strong> -- used the angle of the 2 gradient points, in radians, <em>with incorrect results!</em></li> <li><strong>Translation x</strong> -- tried 1st gradient point's X, also tried 0, <em>with incorrect results!</em></li> <li><strong>Translation y</strong> -- tried 1st gradient point's Y, also tried 0, <em>with incorrect results!</em></li> </ol> <hr> <h2>What SVG data can I use to generate a gradient Matrix for Flash?</h2> <p><strong>(Look at the SVG snippet above,</strong> that's all the data I have describing the gradient)</p>
    singulars
    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.
 

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