In 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();
}
...
}