我觉得我应该知道这一点......好吧,我很想得到任何帮助。所以我制作了一个图像滑块类,并且可以正常工作到蒙版的位置。在我的家庭类中,我创建了图像滑块类的实例并相应地定位它。滑块类中的图像位于 0、0 以及我用于遮罩的形状。这是掩码放置在 stage.x = 0 , stage.y = 0 而不是滑块的类 x:0, x:0 的问题。为什么滑块实例显示在正确的位置但实例中的掩码不是?谢谢你的帮助
这是在我的主页类
private function buildSlider() : void {
slider = new Slider(arrSilde);
slider.x = btnWidth + 15;
addChild(slider);
}
这是滑块类
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;
}