How to display child objects in a row, as3

How to display children in a row? In order, I mean 1,2,3,4, etc. Stepping up with a loop or using a timer is what I need.

Add, remove, appear or disappear children, everything can work. I need an easy way to display 1 child every second until it reaches 10.

METHODS ASKED
  addChild, removeChild, AddChildAt, getChildAt, setChildIndex
       visible! for the cycle

Note
My other answers for enlarging a single display object are good, but I don't see how this works with multiple children. I hope others find this question helpful.

+3
source share
1 answer

As for the layout, I would recommend using ViewStack . You would only need to add each child once, and then just loop through the indices of the stack itself.

You can combine this with Timer , re-run it every time the stack index changes. End the countdown and when the timer ends, increase the selected ViewStack child index. When you hit the last child, reset the index to 0 or do something else.


EDIT: , . , - VBox , ViewStack. , , , ViewStack .

, , Flex, MXML, "startTimer()". , CS4, , , :)

package {
import flash.events.TimerEvent;
import flash.utils.*;

import mx.containers.Box;
import mx.containers.VBox;
import mx.containers.ViewStack;
import mx.controls.Label;

public class StackExample extends Box {
    private var stack:ViewStack;
    private var timer:Timer;

    public function StackExample() { 
        super();

        stack = new ViewStack();
        stack.percentHeight = 100;
        stack.percentWidth  = 100;

        //Add some sample children so we can watch
        //the ViewStack increment.  The numbering here
        //is arbitrary
        for(var i:int=0; i<10; i++) {
            stack.addChild(createNewBox(i));
        }

        stack.selectedIndex = 0;
        addChild(stack);
    }

    //Main application will invoke this function to show the ViewStack
    //changing its children every second until the timer is exhausted
    public function startTimer():void {
        timer = new Timer(1000, 10);

        //"false, 0, true" forces the listener to use weak references so 
        //the event will be cleaned up if this class is destroyed
        timer.addEventListener(TimerEvent.TIMER, incrementStack, false, 0, true);

        timer.start();
    }

    private function createNewBox(index:int):Box {
        var newChildBox:VBox = new VBox();
        newChildBox.setStyle("borderStyle", "solid");

        var childLabel:Label = new Label();
        childLabel.percentWidth = 100;
        childLabel.text = "Child: " + index.toString();
        childLabel.setStyle("fontWeight", "bold");

        newChildBox.addChild(childLabel);

        return newChildBox;
    }

    private function incrementStack(event:TimerEvent):void {
        if(stack.selectedIndex < stack.numChildren)
            stack.selectedIndex = stack.selectedIndex + 1;
    }

}

}

0

Source: https://habr.com/ru/post/1738905/


All Articles