createjs

Get last created shape in createjs?


I have a demo file that I load into a player output from Adobe Animate. I want to know if its possible to find the last created shape (or its position or bounds) on the stage in createjs via the ticker? If so how would I go about doing this?

Edit: I have a tutorial animation which scrolls the window it is in. Due to the amount of information in the animation is can scroll a long way down, my plan is to get the last shape added to the stage, and scroll to that point if its not on the screen


Solution

  • It depends on what you mean by "last".

    You could pretty easily reverse-iterate the stage.children, and look for the first item that is a shape. If it was a container, you could look for its last child, etc.

    Once you have a shape instance, you could rely on its x and y position, or look into its graphics instance. The very last instruction is stored on the graphic.command (docs), and is an EaselJS Command object, which has parameters depending on what type it is. For example, check out the Rect command that stores the x,y,w,h of the last drawRect().

    This will at least give you the last vector drawn by EaselJS.

    If you provide more info on what you are trying to do, I might be able to give you more ideas.