簡體   English   中英

設置動畫片段圖像/背景

[英]Setting an movieclips image/background

我有一個按鈕和一個很小的區域,它是一個動畫片段。

我需要的是,按下按鈕時,它將圖像插入到movieClip中,它實際上必須停靠在整個movieclip區域中。

我瀏覽了多個帖子,但他們提供了我無法弄清的大量信息,到目前為止,我已經做了這些事情:

B_Background1.addEventListener(MouseEvent.CLICK, setBackground1);

function setBackground1(event:MouseEvent):void{
    var firstPic:MovieClip = new C_1BackgroundPIC();

    addChildAt(firstPic, C_MainStage);
}

了解,它向按鈕添加了一個事件,然后在函數中創建了一個新的movieClip實例,該實例內部具有Picture,然后將其添加到“ MainStage”,盡管使用C_MainStage無效,因此不起作用,如果我只是將0用作位置,它的確會添加圖片,但是它將其添加至位置0,這是我不想要的...

這是一個好的開始。 當您使用addChildAt ,它期望一個數字作為第二個參數。 大概C_MainStage是您的MovieClip(不是數字)。 大概您想要C_MainStage的當前顯示索引(而不是C_MainStage本身)。 這可以通過使用getChildIndex獲得

請看以下內容:

function setBackground1(event:MouseEvent):void{
    var firstPic:MovieClip = new C_1BackgroundPIC();

    addChildAt(firstPic, getChildIndex(C_MainStage));

    //now, you may need to also resize your picture so it fits in the bounds of C_MainStage, if so, you can do something like this:
    if(firstPic.width >= firstPic.height){
        //if firstPic is wider than it is tall

        //set it's width to the same as C_MainStage
        firstPic.width = C_MainStage.width;

        //now, to keep the aspect ratio (in case they don't match), make the scaleY the same value as the new scaleX
        firstPic.scaleY = firstPic.scaleX
    }else{
        //do the opposite as above since the height is larger than the width
        firstPic.height = C_MainStage.height;
        firstPic.scaleX = firstPic.scaleY;
    }

    //now, you may want to center firstPic in the C_MainStage bounds
    firstPic.x = C_MainStage.x + ((C_MainStage.width - firstPic.width) * .5);
    firstPic.y = C_MainStage.y + ((C_MainStage.height - firstPic.height) * .5)
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM