PDA

View Full Version : Having trouble using functions more than once...


05studios
09-25-2007, 06:02 PM
Hey guys,

Check out the following code (trimmed down)...the rightClick thing should send the user to the next frame, which contains the stuff needed to create a scrollbar, just like on frame 1 (which works in the onAdded thingy there) but I use the same code and it throws me "Error #1009" cannot access a null object or property.

Any ideas? Im Lost.

thanks!


package com.modernmusicians.linkage
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.display.SimpleButton;
import flash.geom.Rectangle;
import flash.display.DisplayObject;

import com.modernmusicians.linkage.SceneAbstract;
import com.modernmusicians.linkage.Communities;
import com.modernmusicians.SceneHandler;
import com.modernmusicians.ui.CustomScrollBar;

public class Models extends SceneAbstract
{
protected var _sceneHandler:SceneHandler;
protected var _scrollbar:CustomScrollBar;
protected var _scrollbar2:CustomScrollBar;


public function Models(sceneHandler:SceneHandler=null)
{
_location = new Point(90, 210);
_sceneHandler = sceneHandler;

addFrameScript(29, stopScene);

}


// I NEED TO RE-USE THE STUFF HERE (FOR SCROLLBARS) LATER ON WHEN I JUMP TO THE NEXT FRAME - Down below rightClick
override protected function onAdded(e:Event):void
{

holder_mc.links_mc.rollOver1_mc.visible = false;
holder_mc.links_mc.rollOver2_mc.visible = false;
holder_mc.links_mc.rollOver3_mc.visible = false;

holder_mc.links_mc.features_but.addEventListener(M ouseEvent.CLICK, featuresClick);
holder_mc.links_mc.location_but.addEventListener(M ouseEvent.CLICK, locationClick);
holder_mc.links_mc.price_but.addEventListener(Mous eEvent.CLICK, priceClick);

holder_mc.links_mc.leftArrow_but.addEventListener( MouseEvent.CLICK, leftClick);
holder_mc.links_mc.rightArrow_but.addEventListener (MouseEvent.CLICK, rightClick);

holder_mc.links_mc.rollOver1_mc.alpha_mc.txt1_mc.g otoAndStop(_language.type);
holder_mc.links_mc.rollOver1_mc.alpha_mc.mask_mc.v isible = false;

holder_mc.links_mc.rollOver3_mc.alpha_mc.txt1_mc.g otoAndStop(_language.type);
holder_mc.links_mc.rollOver3_mc.alpha_mc.mask_mc.v isible = false;

_scrollbar = new CustomScrollBar(holder_mc.links_mc.rollOver1_mc.al pha_mc.txt1_mc, holder_mc.links_mc.rollOver1_mc.alpha_mc.mask_mc, holder_mc.links_mc.rollOver1_mc.scrub_mc);
_scrollbar.scrubBounds = new Rectangle(holder_mc.links_mc.rollOver1_mc.scrub_mc .x, holder_mc.links_mc.rollOver1_mc.scrub_mc.y, 0, holder_mc.links_mc.rollOver1_mc.down_btn.y - holder_mc.links_mc.rollOver1_mc.scrub_mc.y - holder_mc.links_mc.rollOver1_mc.scrub_mc.height - 1);
_scrollbar.showGear();

_scrollbar2 = new CustomScrollBar(holder_mc.links_mc.rollOver3_mc.al pha_mc.txt1_mc, holder_mc.links_mc.rollOver3_mc.alpha_mc.mask_mc, holder_mc.links_mc.rollOver3_mc.scrub_mc);
_scrollbar2.scrubBounds = new Rectangle(holder_mc.links_mc.rollOver3_mc.scrub_mc .x, holder_mc.links_mc.rollOver3_mc.scrub_mc.y, 0, holder_mc.links_mc.rollOver3_mc.down_btn.y - holder_mc.links_mc.rollOver3_mc.scrub_mc.y - holder_mc.links_mc.rollOver3_mc.scrub_mc.height - 1);
_scrollbar2.showGear();




title_mc.gotoAndStop(_language.type);
txt1_mc.gotoAndStop(_language.type);

back_btn.addEventListener(MouseEvent.CLICK, backClick);
}

protected function backClick(e:MouseEvent):void
{
//back click here
}

protected function leftClick(e:MouseEvent):void
{
// left click stuff here
}

// THIS IS THE PLACE THAT IS GIVING ME Error #1009:, says CANT ACCESS A NULL OBJECT..
protected function rightClick(e:MouseEvent):void
{

holder_mc.gotoAndStop(2);

holder_mc.links_mc.rollOver1_mc.visible = false;
holder_mc.links_mc.rollOver2_mc.visible = false;
holder_mc.links_mc.rollOver3_mc.visible = false;

holder_mc.links_mc.features_but.addEventListener(M ouseEvent.CLICK, featuresClick);
holder_mc.links_mc.location_but.addEventListener(M ouseEvent.CLICK, locationClick);
holder_mc.links_mc.price_but.addEventListener(Mous eEvent.CLICK, priceClick);

holder_mc.links_mc.leftArrow_but.addEventListener( MouseEvent.CLICK, leftClick);
holder_mc.links_mc.rightArrow_but.addEventListener (MouseEvent.CLICK, rightClick);

holder_mc.links_mc.rollOver1_mc.alpha_mc.txt1_mc.g otoAndStop(_language.type);
holder_mc.links_mc.rollOver1_mc.alpha_mc.mask_mc.v isible = false;

holder_mc.links_mc.rollOver3_mc.alpha_mc.txt1_mc.g otoAndStop(_language.type);
holder_mc.links_mc.rollOver3_mc.alpha_mc.mask_mc.v isible = false;

_scrollbar = new CustomScrollBar(holder_mc.links_mc.rollOver1_mc.al pha_mc.txt1_mc, holder_mc.links_mc.rollOver1_mc.alpha_mc.mask_mc, holder_mc.links_mc.rollOver1_mc.scrub_mc);
_scrollbar.scrubBounds = new Rectangle(holder_mc.links_mc.rollOver1_mc.scrub_mc .x, holder_mc.links_mc.rollOver1_mc.scrub_mc.y, 0, holder_mc.links_mc.rollOver1_mc.down_btn.y - holder_mc.links_mc.rollOver1_mc.scrub_mc.y - holder_mc.links_mc.rollOver1_mc.scrub_mc.height - 1);
_scrollbar.showGear();

_scrollbar2 = new CustomScrollBar(holder_mc.links_mc.rollOver3_mc.al pha_mc.txt1_mc, holder_mc.links_mc.rollOver3_mc.alpha_mc.mask_mc, holder_mc.links_mc.rollOver3_mc.scrub_mc);
_scrollbar2.scrubBounds = new Rectangle(holder_mc.links_mc.rollOver3_mc.scrub_mc .x, holder_mc.links_mc.rollOver3_mc.scrub_mc.y, 0, holder_mc.links_mc.rollOver3_mc.down_btn.y - holder_mc.links_mc.rollOver3_mc.scrub_mc.y - holder_mc.links_mc.rollOver3_mc.scrub_mc.height - 1);
_scrollbar2.showGear();

}

protected function featuresClick(e:MouseEvent):void
{
//features click stuff
}

protected function locationClick(e:MouseEvent):void
{
// location click stuff
}

protected function priceClick(e:MouseEvent):void
{
// priceClick Stuff
}

}
}

Flash Gordon
09-26-2007, 04:39 AM
Well hello there, In case you are wondering, yes I built that...well not that but the framework you are using..and did it in 4 days as well.

As for your problem, the "null" reference is simply because the object doesn't exist (like you didn't know that yet). You need to wait for its existance before you try to modify it. Try to figure out which object is the null one.

Best wishes and good luck with the project. Hope your deadline isn't as tight mine was.
Cheers

05studios
09-26-2007, 02:53 PM
I believe I have figured out which is NULL. One problem is, I can't get the scripts to work from the frame level, only in the onAdded in the class file. Otherwise it would work perfectly cause the object wouldnt be NULL at that point if I put the scripts on the frame, but they use stuff from a package imported into the DocumentClass, and I cant get that to work on the frame level. It says call to possibly undefined function.

Any ideas?

Maybe I could just use some sort of timer or something a timeout or whatever to trigger the script a split second after they are triggered now?

Flash Gordon
09-26-2007, 03:53 PM
timing it out is only a hack. Do it if you must, but it isn't very eloquiant.

05studios
09-26-2007, 03:59 PM
I dont know what else to do! lol.

I have zero experience with AS3.0, im all AS2.0. I had to do this project with no time to prepare and I have to get it done quick =X

Any suggestions for how to do it more eloquently? lol. I could really use some advice.

Flash Gordon
09-26-2007, 05:51 PM
I'd have to look at the files, and I'm not up for that. My only though is you are getting paid hourly: don't sweat it.

Do what you got to do to get the project done. When I built it my first question to them was "Do you want it built fast or well?"