Search code examples
apache-royale

Apache Royale equivalent to onEnterFrame in Flex?


Some of my legacy Flex applications use onEnterFrame to manage animations and interactions (like whether the spacecraft hits the asteroid in a game). I want to migrate some of this material to Apache Royale. Is there an equivalent of onEnterFrame in Apache Royale, which compiles to JavaScript rather than to a Flash movie? I believe JavaScript does not have an equivalent of a Flash movie's timeline.


Solution

  • Apache Royale offers a choice of component sets. Royale has support for many Apache Flex APIs, but not many Adobe Flash APIs because there is no timeline as you mentioned.

    EnterFrame events are used for many things as you mentioned and what the right replacement is for your app will depend on what you are using that event for.

    If your usage of enterFrame was to run some code every once in a while then:

    • If using the Basic component set, use org.apache.royale.utils.Timer
    • If using the MXRoyale and SparkRoyale component sets, file a feature request to have enterFrame supported on the Application. EnterFrame is technically a Flash API, but it should be easy enough to add support for enterFrame events and tie it to a Timer.

    If you are using enterFrame to synchronize application code with animations then you will need to understand how those animations are going to work in the browser and use whatever update mechanism your animations use.