Hey, I am trying to get SWFaddress hooked up, its kind of working at the moment:
• Clicking buttons changes everything correctly (i.e page title changes, address url changes and also the content in the swf changes fine)
• BUT when I type the url to access a certain page this is not changing anything
Heres the code:
/*
Website's Navigation Class
*/
package
{
import flash.display.*;
import flash.events.*;
import flash.media.*;
import flash.net.*;
import flash.text.*;
import com.utils.LoadXml;
import com.asual.swfaddress.SWFAddressEvent;
import com.asual.swfaddress.SWFAddress;
public class SiteNav extends MovieClip
{
public var navLoadXml:LoadXml = new LoadXml("xml/data.xml");
public var navItem:NavItem;
public var navUrl;
public var pageName;
public var pageTitle;
public var padding = 2;
public var activeBtn;
public var navOrientation;
public var pageAddress;
public function SiteNav()
{
super();
this.addEventListener(Event.ADDED_TO_STAGE, init);
return;
}
private function init(e:Event):void
{
navLoadXml.addEventListener(Event.COMPLETE, buildNav);
}
//Function builds navigation list
private function buildNav(e:Event):void
{
//Add navigation items
for(var i = 0; i < navLoadXml.getXml().page.length(); i++){
//Create new nav item
navItem = new NavItem();
//Position nav items - list can go vertical or horizontial
if(navOrientation == "vertical"){
navItem.x = 10;
navItem.y = 10+(i * (navItem.height+padding));
}else{
navItem.y = 10;
navItem.x = 10+(i * (navItem.width+padding));
}
//Add text to nav item from XML
navItem.label.htmlText = navLoadXml.getXml().page*.title.text();
navItem.navUrl = navLoadXml.getXml().page*.attribute("id").toString();
navItem.pageName = navLoadXml.getXml().page*.title.toString();
//Add nav item to stage
addChild(navItem);
//Setup navItem for use as button
navItem.buttonMode = true;
navItem.mouseChildren = false;
//Setup Mouse Events
navItem.addEventListener(MouseEvent.MOUSE_OVER, navOver);
navItem.addEventListener(MouseEvent.MOUSE_OUT, navOut);
navItem.addEventListener(MouseEvent.CLICK, navClick);
//Sets up initial page
if(i==0) {
pageAddress = navItem.navUrl;
pageTitle = navItem.pageName;
activeBtn = navItem;
activeBtn.gotoAndStop("Click");
}
}
//Listen for address change
SWFAddress.addEventListener(SWFAddressEvent.CHANGE, handleSWFAddressChange);
//Set values for Deep Linking
SWFAddress.setValue(pageAddress);
SWFAddress.setTitle("Sherolin Santos - Photographer | "+pageTitle);
}
private function handleSWFAddressChange(e:SWFAddressEvent) {
var addr = SWFAddress.getValue();
navigateToPage(addr);
}
//Function to naviate to new page
private function navigateToPage(pageId):void
{
switch (pageId) {
case "/home/" :
break;
case "/about/" :
break;
case "/portfolio/" :
break;
}
Main(root).setText(pageAddress);
}
/*
Mouse Events
*/
//Over button
private function navOver(e:MouseEvent):void
{
if(e.currentTarget != activeBtn){
e.currentTarget.play();
}
}
//Off button
private function navOut(e:MouseEvent):void
{
if(e.currentTarget != activeBtn){
e.currentTarget.gotoAndPlay(11);
}
}
//Click button
private function navClick(e:MouseEvent):void
{
//If this is not activeBtn then remove active state from previous button
if(e.currentTarget != activeBtn && activeBtn != null){
activeBtn.gotoAndPlay(11);
}
trace(e.currentTarget);
e.currentTarget.gotoAndStop("Click");
//Set page address to buttons url
pageAddress = e.currentTarget.navUrl;
//Set page title
pageTitle = e.currentTarget.pageName;
//Set values for Deep Linking
SWFAddress.setValue(pageAddress);
SWFAddress.setTitle("Sherolin Santos - Photographer | "+pageTitle);
//Set as activeBtn
activeBtn = e.currentTarget;
}
}
}
Any ideas??