문제

나는 무대에 25 개의 movieclips를 추가하고 x : 0, y : 0에서 애니메이션을 추가하는 Timerevent를 가지고 있습니다. 내가하고 싶은 것은 각 영화 클립 Ay 값이 25px의 값을 무대에 추가 한 것보다 25px 더 할당하는 것입니다. 타이머가 루프를 할 때마다 숫자 값을 증가 시키려고 노력하여 약간의 테스트를 수행했지만 증가하지 않았습니다. For Loop/Array도 사용해야합니까?

미리 감사드립니다. 조노

import flash.events.*;
import caurina.transitions.*;

bringItemsOn();

var itemTimer:Timer;
function bringItemsOn():void {
    itemTimer=new Timer(300);
    itemTimer.addEventListener(TimerEvent.TIMER,itemTimer_tick);
    itemTimer.start();
}

function itemTimer_tick(e:TimerEvent):void {    
    itemTimer.currentCount-1;
    var mc:MovieClip = new MovieClip();
    mc.graphics.beginFill(Math.random() * 0x000000);
    mc.graphics.drawRect(0,0,stage.stageWidth,25);
    mc.x=0;
    mc.y=0;
    addChild(mc);
    Tweener.addTween(mc,{y:Math.random()*1000 - 500,
                             x:0,
                             time:.9,
                             transition:"easeOutExpo"});

    if (itemTimer.currentCount>=25) {
        itemTimer.removeEventListener(TimerEvent.TIMER,itemTimer_tick);
    }
}
도움이 되었습니까?

해결책

솔직히 나는 처음 에이 모든 것을 for 루프로 설정했을 것입니다. 루프를 위해 완료 한 후에는 각 항목을 그에 따라 배치 한 다음 Tweenlite 또는 좋아하는 트윈 패키지를 사용하십시오.

package
{
    import flash.display.Sprite;
    import flash.events.Event;

    import gs.TweenLite;
    import gs.easing.*;

    public class ExampleDocumentClass extends Sprite
    {
        if(stage) _init();
        else addEventListener(Event.ADDED_TO_STAGE, _init(), false, 0, true);
    }
    private function _init(e:Event =null):void
    {
        for(var i:int = 0; i < 25; i++)
        {
            var mc:MovieClip = new MovieClip();
            mc.graphics.beginFill(Math.random() * 0x000000);
            mc.graphics.drawRect(0,0,stage.stageWidth,25);
            //Seperates them by 25, their width, so they will touch.
            mc.x= i * 25; //i * 25 + 1 leaves a space in between.
            mc.y=0;
            addChild(mc);
            TweenLite.to(mc, 0.9, {y:math.random()*1000-500, x: 0, ease: Expo.easeOut});

        if(i == 24) //Total length - 1
        {
            //The loop ended.
        }
    }
}

화면 업데이트는 For 및 While 루프와 같은 코드 블록 내에서 발생하지 않는다는 점에 유의해야합니다. 이전 항목 X가 방금 설정되었을지라도 화면으로 그려지지 않았기 때문에 내가 보여준 방식으로 서로를 기반으로 한 공간을 공간 할 수 없었습니다. 모든 이미지가 같은 너비가 아니라고 말하는 시스템을 구축하려면, 하나는 다시 시작해야합니다. 이벤트가 주어진 로더의 발사가 발생할 때까지 기다려야합니다. 속성. 당신은 단지 25 픽셀을 공간으로 공간하기를 원했고, 그것들은 같은 크기이기 때문에, 우리는 단지 "i"를 사용하여 그들을 분리합니다.

무슨 일이 일어나고 있는지 : i * 25 = 0; i ++; i * 25 = 25; i ++; i * 25 = 50;

보시다시피 우리는 우리가 찾고 있던 간격을 달성했습니다.

브라이언 호지
hodgedev.com blog.hodgedev.com

다른 팁

이것을 사용하십시오 :

 import flash.events.*;
 import caurina.transitions.*;

bringItemsOn();

var extra:int = 0;
var itemTimer:Timer;
function bringItemsOn():void {
    itemTimer=new Timer(300);
    itemTimer.addEventListener(TimerEvent.TIMER,itemTimer_tick);
    itemTimer.start();
}

function itemTimer_tick(e:TimerEvent):void {    
    itemTimer.currentCount-1;
    var mc:MovieClip = new MovieClip();
    mc.graphics.beginFill(Math.random() * 0x000000);
    mc.graphics.drawRect(0,0,stage.stageWidth,25);
    mc.x += extra;
    mc.y=0;
    extra = mc.width;
 /*u can use mc's width for different x value's or

make ur own like extra += 10; each mc.x will be different */
    addChild(mc);
    Tweener.addTween(mc,{y:Math.random()*1000 - 500,
                             x:0,
                             time:.9,
                             transition:"easeOutExpo"});

    if (itemTimer.currentCount>=25) {
        itemTimer.removeEventListener(TimerEvent.TIMER,itemTimer_tick);
    }
}

변수를 증가 시키거나 25px를 y에 추가하려고 시도한 부분을 실제로 찾지 못했지만 다음을 시도하십시오.

function itemTimer_tick(e:TimerEvent):void {

    ...

    mc.y = itemTimer.currentCount * 25;
    addChild(mc);

    ...

}

나는 정말로 다른 접근법은 그것을 사용하는 것입니다 delay 의 속성 Tweener.addTween 방법. 모든 movieclips를 시작하고 조금만 지연을 늘리나요?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top