After doing some digging about I found some discussion on this mailing list
saying that you couldn't load a Sprite into a Panel or something along those
lines. I changed it to a canvas instead and it's now working fine.

 

It seems that the example on livedocs should be updated.

 

Giles Roadnight

  _____  

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Giles Roadnight
Sent: 22 December 2006 00:42
To: [email protected]
Subject: [flexcoders] masking with a sprite

 

Hi

 

I am loading swfs from a backend server that are produced by our own
renderer. If I simply load these swfs into an image the background colour
form the swf floods the whoel stag enad makes it impossible to see anything
other than the last one to load.

 

I need to mask the swfs so we just see what we are supposed to.

 

I found an example in the help for the DisplayObject class. It seemed to do
everything that I wanted - it used a Sprite, drew a rectangle on it, added
it as a child then set it as a mask.

 

However when I try this when the addchild function is called saying that it
cannot convert the Sprite to a Display object:

 

Type Coercion failed: cannot convert flash.display::[EMAIL PROTECTED] to
mx.core.IUIComponent.

 

What am doing wrong? I hope someone can help.

 

The example I was looking at is:

 

import flash.text.TextField;
import flash.display.Sprite;
import flash.events.MouseEvent;
 
var tf:TextField = new TextField();
tf.text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, " 
            + "sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. "
tf.selectable = false;
tf.wordWrap = true;
tf.width = 150;
addChild(tf);
 
var square:Sprite = new Sprite();
square.graphics.beginFill(0xFF0000);
square.graphics.drawRect(0, 0, 40, 40);
addChild(square);
 
tf.mask = square;
 
tf.addEventListener(MouseEvent.MOUSE_DOWN, drag);
tf.addEventListener(MouseEvent.MOUSE_UP, noDrag);
 
function drag(event:MouseEvent):void {
    square.startDrag();
}
function noDrag(event:MouseEvent):void {
    square.stopDrag();

}

 

Giles Roadnight

 

 

Reply via email to