Pregunta

Tengo un timerEvent que agrega 25 movieclips al escenario y los anima desde x: 0, y: 0, ¡todo esto funciona bien! Lo que me gustaría hacer es asignar a cada clip de película un valor de y 25px más que el último clip de película agregado al escenario. Hice una pequeña prueba al intentar incrementar un valor numérico cada vez que el temporizador hacía un bucle pero no se incrementaba. ¿Debo usar un bucle / matriz también?

Gracias de antemano. Jono

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);
    }
}
¿Fue útil?

Solución

Honestamente, habría configurado todo esto inicialmente con un bucle for. Una vez que haya terminado su bucle for, coloque cada elemento en consecuencia, luego use TweenLite, o su paquete de interpolación favorito.

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.
        }
    }
}

Es importante tener en cuenta que las actualizaciones de la pantalla NO se producen dentro de los bloques de código, como los bucles for y while. No podría separarlos de la forma en que lo he mostrado, porque aunque los elementos anteriores x pueden haberse configurado, no se han dibujado a la pantalla; Para construir un sistema donde, por ejemplo, todas las imágenes no tienen el mismo ancho, pero una debe comenzar tras otra, debemos esperar a que se active el evento Event.COMPLETE para el cargador dado, de modo que podamos acceder a su ancho y otros atributos Como solo quería separarlos con 25 píxeles, y son del mismo tamaño, simplemente usamos " i " para separarlos

¿Qué está pasando? i * 25 = 0; i ++; i * 25 = 25; i ++; i * 25 = 50;

como puede ver, hemos logrado el espacio que buscábamos.

Brian Hodge
hodgedev.com blog.hodgedev.com

Otros consejos

usa esto:

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

Realmente no localizó la parte en la que intentó incrementar una variable o agregar 25px a y, pero intente esto:

function itemTimer_tick(e:TimerEvent):void {

    ...

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

    ...

}
El enfoque

realmente diferente podría ser utilizar la propiedad delay del método Tweener.addTween . ¿Iniciar todos los clips de video y aumentar un poco el retraso para cada uno?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top