2012-01-17 94 views
0

我覺得我應該知道這個......好吧,我會喜歡任何幫助。所以我製作了一個圖像滑塊類,並且可以正常工作到掩碼的位置。在我的家庭類中,我製作了一個圖像滑塊類的實例並相應地定位它。滑塊類中的圖像位置爲0,0以及我用於掩碼的形狀。這裏是掩模放置在stage.x.x = 0,stage.y = 0而不是滑塊的Class x:0,x:0的問題。爲什麼滑塊實例顯示正確的位置,但實例中的掩碼不是?感謝您的幫助Adob​​e Flash AS3掩模放置

這是我的主頁類

private function buildSlider() : void { 
    slider = new Slider(arrSilde); 
    slider.x = btnWidth + 15; 
    addChild(slider); 
    } 

這是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; 
    } 
+0

你在哪裏addChild()掩碼對象?我在代碼中的任何地方都看不到它。並且:您是否試圖追蹤masker.x和masker.y? – 2012-01-17 14:58:05

+0

非常感謝你看完 – 2012-01-19 09:12:24

回答

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); 
    } 
+0

我忘了把掩碼添加到顯示列表謝謝 – 2012-01-19 09:13:35