AS3 Dynamic Alpha Gradient Mask
Posted by Matthew Hancock
Tutorials July 16th, 2007 at 2:18 pmIn the process of creating an image gallery in AS3, I ran across this interesting error.
1118: Implicit coercion of a value with static type flash.display:DisplayObject to a possibly unrelated type flash.display:MovieClip.
Incorrect Code:
public class ImageGallery extends Component {
private var ldrData:URLLoader;
private var count:uint;
var holder:MovieClip;
var myMask:MovieClip;
public function ImageGallery() {
count = 0;
myMask = new MovieClip();
holder = new MovieClip();
addChild(holder);
holder.x = 50;
holder.y = 0;
myMask = addChild(new mask_mc());
holder.cacheAsBitmap = true;
myMask.cacheAsBitmap = true;
holder.mask = myMask;
if (this.stage != null) {
//Master.SetParameter("ModelId","100")
this.Initialize();
}
}
...
}
The fix for this error was simple. When declaring myMask = addChild(new mask_mc()), you can cast your variable using “as MovieClip” to fix the problem.
Corrected Code:
public class ImageGallery extends Component {
private var ldrData:URLLoader;
private var count:uint;
var holder:MovieClip;
var myMask:MovieClip;
public function ImageGallery() {
count = 0;
myMask = new MovieClip();
holder = new MovieClip();
addChild(holder);
holder.x = 50;
holder.y = 0;
myMask = addChild(new mask_mc()) as MovieClip;
holder.cacheAsBitmap = true;
myMask.cacheAsBitmap = true;
holder.mask = myMask;
if (this.stage != null) {
//Master.SetParameter("ModelId","100")
this.Initialize();
}
...
}

August 27th, 2007 at 9:36 am
Cheers for this. I’ve stupidly been developing in the Flash CS3 IDE with AS3 Strict mode set to off and have been pulling my hair out. After seeing this post I realised I wasn’t defining what my added child should be; a movieclip.
KJ