Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting an <mx:Image> as a mask on a <s:Graphic> through <s:mask> doesn't work. but AS does
    primarykey
    data
    text
    <p>I'm having trouble setting up a Graphic object (a solid filled rectangle) to be masked with an image that gets loaded at runtime. I've managed to get it to work with the following code:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="init()" &gt; &lt;fx:Script&gt; &lt;![CDATA[ import spark.core.MaskType; public function init():void { rect.mask = circle; } ]]&gt; &lt;/fx:Script&gt; &lt;s:Graphic id="rect" maskType="{MaskType.ALPHA}" cacheAsBitmap="true"&gt; &lt;s:Rect width="500" height="500"&gt; &lt;s:fill&gt; &lt;s:SolidColor color="0xDDAAAA" /&gt; &lt;/s:fill&gt; &lt;/s:Rect&gt; &lt;/s:Graphic&gt; &lt;mx:Image id="circle" source="http://example.com/someimage.png" cacheAsBitmap="true" /&gt; &lt;/s:Application&gt; </code></pre> <p>What I don't understand is why it does not work with this other snippet, modified slightly from the O'Reilly Flex 4 Cookbook (<a href="http://oreilly.com/flex/excerpts/flex-4-cookbook/graphics.htm" rel="nofollow">Chapter 4 - Apply Bitmap Data to a Graphic Element as a Mask</a>):</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" &gt; &lt;fx:Script&gt; &lt;![CDATA[ import spark.core.MaskType; ]]&gt; &lt;/fx:Script&gt; &lt;s:Graphic id="rect" maskType="{MaskType.ALPHA}" cacheAsBitmap="true"&gt; &lt;s:Rect width="500" height="500"&gt; &lt;s:fill&gt; &lt;s:SolidColor color="0xDDAAAA" /&gt; &lt;/s:fill&gt; &lt;/s:Rect&gt; &lt;s:mask&gt; &lt;mx:Image id="circle" source="http://example.com/someimage.png" cacheAsBitmap="true" /&gt; &lt;/s:mask&gt; &lt;/s:Graphic&gt; &lt;/s:Application&gt; </code></pre> <p>Setting the PNG inside the &lt;s:mask&gt; makes the stage render nothing, while adding the mask programatically in the init() method causes correct behaviour. </p> <p>It took me quite a while to figure this out and I'd like to understand what it is that I'm doing incorrectly in the MXML approach, as that seems to be what is being done in the Cookbook (other than me using an Image and the example using a Group wrapped BitmapImage).</p> <p>Thanks</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.
    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