How to do (back & forward) like website in flash lite?
Hi all,
It's my first topic and i need some help in my app
My app containts pages(like website) and i want to browsing them
by right and left keys..back and forward how can i do that?
And i will put this information inside a dynamic text and creating a veriable holding information..is there a better way than this?
Thanks in advance
Re: How to do (back & forward) like website in flash lite?
Hi issanasr13,
The way I would do it is to set up an array of names for your pages, then increase and decrease a page number variable with a Left and Right key press, which will reference the pages in the array.
[CODE]
// Set up pages array
var pages_array:Array = new Array();
pages_array[0] = "home";
pages_array[1] = "about";
pages_array[2] = "links";
// initialise page number and name
var pageNum:Number = 0;
var pageName:String = pages_array[pageNum];
// set up key listener and Key class
var keyListener:Object = new Object();
keyListener.onKeyDown = onKeyDownHandler;
Key.addListener(keyListener);
// function to handle the key press
function onKeyDownHandler():Void {
// store the key that has been pressed
var keyCode:Number = Key.getCode();
if (keyCode == Key.LEFT){
// decrease the pageNum variable
if (pageNum > 0){
pageNum--;
setPage();
}
} else if (keyCode == Key.RIGHT){
// increase the pageNum variable
if (pageNum < 2){
pageNum++;
setPage();
}
}
}
// function to handle the new page
function setPage():Void {
pageName = pages_array[pageNum];
trace("pageNum = " + pageNum);
trace("pageName = " + pageName);
// put some code here to load the new page
// or goto a frame on the timeline, etc
// based on the value of pageName
}
[/CODE]
Hope this helps.
Paul
Re: How to do (back & forward) like website in flash lite?
Thanks very much PaulLamonby for your help ..but i have one query about the last code
[QUOTE]// function to handle the new page
function setPage():Void {
pageName = pages_array[pageNum];
trace("pageNum = " + pageNum);
trace("pageName = " + pageName);
this._parent._parent.attachMovie("page1")
this._parent._parent.attachMovie("page2")
}[/QUOTE]
It didn't work like this..what i should write instead of the last 2 lines
And by the way my pages are Movieclips(page1,page2 and page3..etc)
Thanks again
Re: How to do (back & forward) like website in flash lite?
Hi issanasr13,
What timeline have you written the code on? This will determine what path you need to use to load the 'pages'. I suggest placing all your code on the _root timeline in frame 1.
You also need to use the correct parameters when using attachMovie(idName, instanceName, depth)
e.g. If your code is on the _root timeline, the code below will attach a movieClip from the library, with a linkage ID name of 'home' to the _root timeline. It will have an instance name of 'home_mc' and a depth relevant to the next highest available depth.
[CODE]// Set up pages array
var pages_array:Array = new Array();
pages_array[0] = "home";
pages_array[1] = "about";
pages_array[2] = "links";
// initialise page number and name
var pageNum:Number = 0;
var pageName:String;
// function to handle the new page
function setPage():Void {
pageName = pages_array[pageNum];
var instanceName:String = pageName + "_mc";
this.attachMovie(pageName, instanceName, this.getNextHighestDepth());
}
// call the setPage function
setPage();[/CODE]
Regards
Paul