Views (pages) without timeline
I have a relativly simple question. What would be the best way to recreate a multiple page application without using the timeline. I created a pagemanager class that add's and removes classes, with classes acting as pages. Now this doesn't really seem like a very effective method. I believe flex offers a similiar approach as HTML, but it's already to late to m开发者_JAVA技巧ove to flex at this point.
Any suggestions? Thanks in advance.
I recommend you create an own class that works similar as the viewstack in Flex. Use it with an interface (for example IPage) to force methods that you viewstack uses to load and unload/dispose the pages. Once you run the changePage method on the viewstack, you dispose the current page and open the new page. When you have this running it is easy to add transitions.
Something like this (This code is NOT validated):
_view = new ViewStack();
_view.addPage(Pages.INTRO, new IntroPage());
_view.addPage(Pages.OUTRO, new OutroPage());
_view.changePage(Pages.INTRO);
IPage.as
package
{
public interface IPage
{
function open() : void
function close() : void
}
}
ViewStack.as
package
{
import flash.display.Sprite;
public class ViewStack extends Sprite
{
public function ViewStack()
{
super();
}
public function addPage(pageID : String, page : IPage) : void
{
// add page to list
}
public function removePage(pageID : String) : void
{
// remove page from list
}
public function changePage(pageID : String) : void
{
if(_currentPage)
{
_currentPage.close();
removeChild(_currentPage);
}
_currentPage = getPageById(pageID);
_currentPage.open();
addChild(_currentPage);
}
}
}
精彩评论