PDA

View Full Version : CS3 Error #1009 when trying to use swf address in a document class...



widecircle
August 19th, 2008, 07:43 AM
I'm trying to have a document class using SWFAddress & gSkinners framescript manager class but keep getting SWFAddress errors...
This is the error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.asual.swfaddress::SWFAddress$/::_getValue()
at com.asual.swfaddress::SWFAddress$/::_check()
at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
at flash.utils::Timer/flash.utils:Timer::tick()

This is the documentclass code:


package {

import flash.events.*;
import com.gskinner.utils.FrameScriptManager;
import flash.display.*;
import com.asual.swfaddress.*;
import caurina.transitions.*;
import caurina.transitions.properties.*;

public class Website extends MovieClip {

// constructor:
public function Website() {

//FrameScript setup
super();
SWFAddress.addEventListener(SWFAddressEvent.CHANGE , handleSWFAddress);
var fsm:FrameScriptManager = new
FrameScriptManager(this);
fsm.setFrameScript("$/",homeFunct);
fsm.setFrameScript("$/about/",aboutFunct);
fsm.setFrameScript("$/portfolio/",portfolioFunct);
fsm.setFrameScript("$/contact/",contactFunct);



}

// public getter/setters:

//**********************************************
// SWFAddress
//**********************************************
// Custom utilities
public function replace(str, find, replace):String {
return str.split(find).join(replace);
}

public function toTitleCase(str):String {
return str.substr(0,1).toUpperCase() + str.substr(1).toLowerCase();
}

public function formatTitle(addr):String {
if (addr.substr(addr.length - 1, 1) == '/') {
addr = addr.substr(0, addr.length - 1);
}
return 'Webbmall' + ((addr.length > 0) ? ' / ' + toTitleCase(replace(addr.substr(1), '/', ' / ')) : '');
}

// SWFAddress handling
public function btnClick(event:MouseEvent):void {
SWFAddress.setValue(event.target.link);
}

public function btnRollOver(event:MouseEvent):void {
SWFAddress.setStatus(event.target.link);
}

public function btnRollOut(event:MouseEvent):void {
SWFAddress.resetStatus();
}

public function handleSWFAddress(event:SWFAddressEvent):void {
if (currentFrame == 2 && event.value == '') {
play();
} else {
gotoAndStop('$' + event.value);
if (currentLabel == null) {
gotoAndStop('$/error/');
}
}
SWFAddress.setTitle(formatTitle(event.value));
}

// private methods, webbsidans olika sektioner:

//***************************************
// Hem - home
//***************************************

private function homeFunct():void {
// trace("hem");
stop();

}

//**************************************
// About - Om oss
//**************************************

private function aboutFunct():void {
// trace("om oss");
//
}

//***************************************
// Portfolio
//***************************************
// trace("portfolio");
//
}



//*********************************************
// Kontakt - contact
//*********************************************
private function contactFunct():void {
//trace("kontakt");

}


}
} I would really appreciate some help with this one.
I've read that it's usually an issue of stage or root access but I'm not sure - still new to AS3.
I also have some preload code on frame 1 in the movie:


function enterFrame(e:Event){
var bl:int = loaderInfo.bytesLoaded;
var bt:int = loaderInfo.bytesTotal;
if (bl && bt && bl == bt) {
removeEventListener(Event.ENTER_FRAME, enterFrame);
nextFrame();
} else if (loading_mc.bar_mc) {
loading_mc.bar_mc.scaleX = bl/bt;
}
}
addEventListener(Event.ENTER_FRAME, enterFrame);
stop(); All the best, Niklas

Felixz
August 19th, 2008, 09:38 AM
The code from 1st frame can be moved to DocumentClass.

Super is useless; it does nothing.

The problem with SWFAddress usually caused by adding a listener in DocumentClass constructor/1st frame.
To avoid it you can add it in other frame or wait some miliseconds. Also you can try an experimantal class modified by me to fit AS3 style (this means changed syntax).

widecircle
August 20th, 2008, 02:56 AM
Actually the super code was there in an example that was included when I downloaded gSkinner's framescript manager class...I'm not sure why gskinner have it there.
Thanks for sharing your files - however, I got an answer from Rostislav over at the SWFAddress forum where he told me to update to the latest SVN code & that seems to have solved the problem...

Niklas :hoser: