我觉得我应该知道这一点......好吧,我会喜欢任何帮助。所以我制作了一个图像滑块Class,可以正常工作到面具的位置。在我的Home Class中,我创建了一个图像滑块Class的实例并相应地定位它。滑块Class中的图像位于0,0以及我用于蒙版的形状。这是掩码放置在stage.x = 0,stage.y = 0而不是滑块的类x:0,x:0的问题。为什么滑块实例显示在正确位置但实例中的掩码不是?谢谢你的帮助
这是在我的HomePage Class
中 private function buildSlider() : void {
slider = new Slider(arrSilde);
slider.x = btnWidth + 15;
addChild(slider);
}
这是Slider Class
private var t : Timer;
private var counter : int;
private var slideArr : Array;
private var currentSlide : HomeSliderPageObj;
private var oldSlide : HomeSliderPageObj;
private var masker : Shape;
public function Slider(_arr : Array) {
super();
slideArr = _arr;
currentSlide = _arr[counter];
buldSlider();
addChild(currentSlide.image);
t = new Timer(2000);
t.addEventListener(TimerEvent.TIMER, changeSlide);
t.start();
}
private function buldSlider() : void {
masker = new Shape;
masker.graphics.lineStyle();
masker.graphics.beginFill(0x000000, 1);
masker.graphics.drawRect(0,0, currentSlide.image.width, currentSlide.image.height);
masker.graphics.endFill();
masker.x = currentSlide.image.x;
masker.y = currentSlide.image.y;
this.mask = masker;
}
private function changeSlide (event : TimerEvent) : void {
if (counter >= slideArr.length){ counter = 0; }
else { ++counter; }
oldSlide = currentSlide as HomeSliderPageObj;
addChild(oldSlide.image);
removeChild(currentSlide.image);
currentSlide = slideArr[counter];
currentSlide.image.x = currentSlide.image.width;
addChild(currentSlide.image);
TweenMax.to(oldSlide.image, .5, {x:oldSlide.image.width*(-1), onComplete:clean});
TweenMax.to(currentSlide.image, .5, {x:0});
}
private function clean () : void {
removeChild(oldSlide.image);
oldSlide = null;
}
答案 0 :(得分:0)
看看是否有效。
currentSlide = _arr[counter];
buldSlider(); //this creates the mask shape
addChild(currentSlide); //this add the image movieclip
currentSlide.mask = masker; //this sets the masking
private function buldSlider() : void {
masker = new Shape;
masker.graphics.lineStyle();
masker.graphics.beginFill(0x000000, 1);
masker.graphics.drawRect(0,0, currentSlide.image.width, currentSlide.image.height);
masker.graphics.endFill();
masker.x = currentSlide.image.x;
masker.y = currentSlide.image.y;
addChild(masker);
}