PDA

View Full Version : Accessing objects with linked classes


Mattaus22
09-15-2010, 11:23 PM
So I have a menu built inside of Flash CS4 that has a graphic for a background and five text fields that sit on it for menu options. The whole thing is saved as a movie clip in the library. The text fields all have instance names like infoBtn and mapBtn etc. and the menu is already on the stage and linked to it's own class in the library. My problem is accessing those text fields on the menu from the class. I keep getting "Error #1009: Cannot access a property or method of a null object reference." and the menu doesn't work. But if I trace the infoBtn.text in the class it outputs the text that is in the text field. So the code is accessing it but it's still not working??? :confused: I have my code for the class listed below. Thank you for any help.

package classes
{
import flash.display.*;
import flash.events.*;
import flash.text.*;
import com.greensock.*;
import com.greensock.easing.*;

public class FlyOutMenu extends MovieClip
{
public var menuArray:Array = [infoBtn, agentBtn, calcBtn, mapBtn, flyerBtn];
public var showMenu:Number = 200;
public var hideMenu:Number = 35;

public function FlyOutMenu() // something about the document class??
{
trace(infoBtn);
for (var i:int = 0; i < menuArray.length; i++)
{
menuArray[i].addEventListener(MouseEvent.CLICK, menuContent);
}
}

public function menuContent(e:MouseEvent):void
{
trace(infoBtn.text);
switch(e.target)
{
case infoBtn:
gotoAndStop(3);
break;
case agentBtn:
gotoAndStop(4);
break;
case calcBtn:
gotoAndStop(5);
break;
case mapBtn:
gotoAndStop(6);
break;
case flyerBtn:
gotoAndStop(7);
break;
}
}

public function menuOut(e:MouseEvent):void
{
TweenLite.to(e.target, .4, {x:showMenu,ease:Linear.easeNone});
}

public function menuIn(e:MouseEvent):void
{
TweenLite.to(e.target, .4, {x:hideMenu,ease:Linear.easeNone});
}
}
}