[FONT=Arial]Hey guys, I am new to writing about my as3 trouble shoots. There is a TypeError with bringing my code from the timeline to a new Main.as. When debugging it says that my ‘slide’ in slideIn and slideOut function towards the bottom of the code = null?[/FONT] This worked on the timeline. Is there anything I am missing when i convert to classes?
TypeError: Error #1009: Cannot access a property or method of a null object reference.
[COLOR=DimGray][SIZE=2] [SIZE=1]at classes.com.project::Main/slideOut()[\TERASERVER\production\LIQUID\CLIENTS\Liquid\Liquid Exchange\ActionScript\project templates\v2_classes\src\classes\com\project\Main.as:220]
at classes.com.project::Main/nextSlide()[\TERASERVER\production\LIQUID\CLIENTS\Liquid\Liquid Exchange\ActionScript\project templates\v2_classes\src\classes\com\project\Main.as:186]
at classes.com.project::Main/transitionIn()[\TERASERVER\production\LIQUID\CLIENTS\Liquid\Liquid Exchange\ActionScript\project templates\v2_classes\src\classes\com\project\Main.as:38]
at classes.com.project::Main/init()[\TERASERVER\production\LIQUID\CLIENTS\Liquid\Liquid Exchange\ActionScript\project templates\v2_classes\src\classes\com\project\Main.as:30]
at classes.com.project::Main()[\TERASERVER\production\LIQUID\CLIENTS\Liquid\Liquid Exchange\ActionScript\project templates\v2_classes\src\classes\com\project\Main.as:27][/SIZE][/SIZE][/COLOR]
package classes.com.project {
[SIZE=1]import flash.display.*;
import flash.display.MovieClip;
import flash.display.LoaderInfo;
import flash.events.*;
import flash.events.IOErrorEvent;
import flash.events.HTTPStatusEvent;
import flash.text.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import gs.*;
import gs.easing.*;
import classes.com.project.*;[/SIZE]
public class Main extends MovieClip{
public var slides:Array = [slide1, slide2, slide3];
public var buttons:Array = [btn1, btn2, btn3,];
public var slideIndex:int = 0;
public var lastSlideIndex:int = 0;
public var timerActive:Boolean = true;
public function Main(){
init();
}
public function init():void{
transitionIn();
configButtons();
}
public function transitionIn():void{
//TweenMax.to(this, 2, {alpha:1, ease:Cubic.easeOut});
nextSlide();
}
//////// CTRL BTNS ////////////////////////
public function configButtons():void{
//trace('configMainButtons');
configButton(btn1);
configButton(btn2);
configButton(btn3);
}
public function configButton(btn:MovieClip):void{
btn.addEventListener(MouseEvent.CLICK, onClickButton);
btn.addEventListener(MouseEvent.ROLL_OVER, onRollOverButton);
btn.addEventListener(MouseEvent.ROLL_OUT, onRollOutButton);
btn.mouseChildren = false;
btn.buttonMode = true;
btn.mouseEnabled = true;
}
public function onClickButton(e:MouseEvent):void{
allButtonsRollOut();
TweenMax.killTweensOf(this);
timerActive = false;
e.target.removeEventListener(MouseEvent.CLICK, onClickButton);
e.target.removeEventListener(MouseEvent.ROLL_OVER, onRollOverButton);
e.target.removeEventListener(MouseEvent.ROLL_OUT, onRollOutButton);
slideIndex = buttons.indexOf(e.target);
nextSlide();
}
public function onRollOverButton(e:MouseEvent):void{
var btnTarget:MovieClip = e.target as MovieClip;
buttonRollOver(btnTarget);
}
public function onRollOutButton(e:MouseEvent):void{
var btnTarget:MovieClip = e.target as MovieClip;
if (lastSlideIndex != buttons.indexOf(e.target)) {
buttonRollOut(btnTarget);
}
}
public function buttonRollOver(btnTarget:MovieClip):void{
TweenMax.to(btnTarget.getChildByName('overBtn'), .3, {alpha:1, ease:Cubic.easeOut});
}
public function buttonRollOut(btnTarget:MovieClip):void{
TweenMax.to(btnTarget.getChildByName('overBtn'), .3, {alpha:0, ease:Cubic.easeOut});
btnTarget.addEventListener(MouseEvent.CLICK, onClickButton);
btnTarget.addEventListener(MouseEvent.ROLL_OVER, onRollOverButton);
btnTarget.addEventListener(MouseEvent.ROLL_OUT, onRollOutButton);
}
public function allButtonsRollOut():void{
buttonRollOut(btn1);
buttonRollOut(btn2);
buttonRollOut(btn3);
slideOut(slide1);
slideOut(slide2);
slideOut(slide3);
}
//////// NEXT SLIDE ///////////////////////
public function nextSlide():void {
trace("slide ", slideIndex);
if(slideIndex >= slides.length){
slideIndex = 0;
}
TweenMax.killTweensOf(this);
slideOut(slides[lastSlideIndex]);
if (buttons[lastSlideIndex] != null) {
buttonRollOut(buttons[lastSlideIndex]);
}
if (slideIndex >= slides.length) {
slideIndex = 0;
}
slideIn(slides[slideIndex]);
lastSlideIndex = slideIndex;
if (buttons[slideIndex] != null) {
buttonRollOver(buttons[slideIndex]);
}
if (timerActive) {
TweenMax.to(this, 0, {delay:10, onComplete:nextSlide});
}
slideIndex++;
}
public function slideIn(slide:MovieClip):void {
TweenMax.to(**slide**, 1, {alpha:1, ease:Cubic.easeOut});
}
public function slideOut(slide:MovieClip):void {
TweenMax.to(**slide**, .5, { alpha:0, ease:Cubic.easeOut});
}
}
}
Any help?