PDA

View Full Version : SFWaddress



evokenz
July 1st, 2009, 05:49 PM
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[i].title.text();

navItem.navUrl = navLoadXml.getXml().page[i].attribute("id").toString();

navItem.pageName = navLoadXml.getXml().page[i].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??

final_end
July 1st, 2009, 05:58 PM
doesnt look like you have anything looking for onChange.

as in


SWFAddress.onChange = function() {
var value = SWFAddress.getValue();
if (value == '/sweepstakes/') {
//do actions or jump to the part in the swf it should

}
else if (value == '/gassweepstakes/' ) {
//perform other actions and jump to other part of swf
}
}

evokenz
July 1st, 2009, 06:11 PM
im pretty sure thats what this code is doing?



...
//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);
}


Your code is AS2??

Bronx fan?

final_end
July 1st, 2009, 06:18 PM
ah sorry, yeah it was in as2, but the logic is the same.

i was in the bronx for a while. can't beat arthur ave. for italian anywhere in the whole city.

the navigateToPage function... I would think that is where you tell it to jump to the point you want. i see you looking for the cases but not doing anything specific for each of them. only settingText somewhere.

so like
case "/home/" : gotoAndStop("home"); break;


or something like that

evokenz
July 1st, 2009, 06:36 PM
hmmm.. i'll keep on trying...

.ral:cr
July 2nd, 2009, 12:54 AM
what do you expect to see?
the actions from navClick will not get executed, only from navigateToPage, so the proper way of working with swfaddress is to move everything in the navigateToPage

evokenz
July 5th, 2009, 08:39 PM
I'm still having trouble with this, so if anyone is keen to help here is the source:
http://www.ethoscreative.co.nz/Sherolin/
Thanks