-
Notifications
You must be signed in to change notification settings - Fork 4
4. Using Custom Page Classes in Glory
There will come a time when you want to do something fancier than a slide show using this framework. This can be done by creating a custom page class. The examples currently have demo classes in the /src/pages directory to show how this works.
The class name should start with a capital P with the id of your page after that. So for a page with id of "svg", just create a page class of "Psvg" that extends PageComponent, and you're ready to go:
package pages;
import ca.confidant.glory.view.components.PageComponent;
import ca.confidant.glory.view.components.ActorComponent;
import haxe.Timer;
import motion.Actuate;
import motion.easing.Quad;
class Psvg extends PageComponent{
private var myTimer:Timer;
private var star:ActorComponent;
public function new(){
super();
this.alpha=1;
x=-960;
}
override public function init(){
star=myActors.get("star1");
startTimer();
}
public function startTimer(i:Int=50):Void{
//trace("startTimer!");
myTimer=new Timer(i);
myTimer.run = onTimerTick;
}
private function onTimerTick():Void{
star.rotation+=20;
}
override public function transitionIn():Void{
trace(this.name+" in!");
Actuate.tween (this, 1, { x: 0 }, false).ease (Quad.easeIn);
}
/*
* Gets called before page destroy
*/
override public function transitionOut():Void{
Actuate.tween (this, 1, { alpha:0 }, false).ease (Quad.easeOut);
}
}
The init() function gets called once the page has been built and has instances of all its actors. That is where you should start with any code that needs instances of those actors. References to all of them are stored in a Map called “myActors”. Just retrieve them using the actor id as a key, like illustrated above. It is also possible to retrieve assets directly from the OpenFL Assets class if desired.
IMPORTANT: It is necessary to do imports of your custom page classes in your Main class. This is so they get compiled into the application for later use.