ah, i cant figure this out
i have a slide to control the volume of a song it links to that autoplays when it starts
its a blank .fla with the class Volume and an as3 file called Volume with all the codes
by itself, it works perfect, but when i go to my index.fla where i try to use a UILoader to load the blank swf called volume
it says:
" TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Volume() "
what do you think could be happening?
Go into your Publish Settings and in the Flash section select the option to Permit Debugging. Run the file and the error message should include a line number for the offending code. The 1009 error indicates that whatever object is being targeted on that line does not exist as far as the code sees it.
im not using code on the index.fla for it i put a UI Loader and put the folderadress in the source blank in its properties,
i mean, i do have code in the index just not having anything to do with the UILoader or its source. the UI loader is in frame 1, wich i named "musicframe"
the only other action i have in that frame is on a layer above and its only a stop().
the code for the as file class "Volume" is
package
{
import flash.display.Sprite;
import flash.display.Graphics;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
import flash.geom.Rectangle;
public class Volume extends Sprite
{
public var snd:Sound = new Sound();
public var channel:SoundChannel = new SoundChannel();
//Make sure you pass URLRequest an audio file on your computer.
public var req:URLRequest = new URLRequest("underwater.mp3");
public var boundary:Rectangle;
public var sprite:Sprite;
public var slider:Sprite;
public var xPos:Number = stage.stageWidth / 2;
public var yPos:Number = stage.stageHeight / 2;
public var vol:Number;
/*
Our request is loaded into the sound object and plays through
our channel. Volume is initially set at 50% and passed as a
transformation to our our channels soundTransform property
(a fancy way of saying volume). The init() function is called.
*/
public function Volume()
{
snd.load(req);
channel = snd.play();
vol = .5;
channel.soundTransform = new SoundTransform(vol);
init();
}
/*
The init function creates and draws a rectangle and circle
to the stage and centers them based on the height and
width of the stage. In addition, a rectangle object is
created to 'contain' the sliding circle, like an imaginary box.
We pass -100 as the x value because it is added relative
to our sprite. If we set its x value at 0, or the sprites default x
value,the boundary would stop and start at the slider sprite. Change
-100 to 0 in the rectangle object to get a better idea of its use.
*/
public function init():void
{
sprite = new Sprite();
sprite.graphics.beginFill(0x666666);
sprite.graphics.drawRect(xPos,yPos,200,2);
sprite.graphics.endFill();
addChild(sprite);
sprite.x -= sprite.width / 2;
slider = new Sprite();
slider.graphics.beginFill(0x999999);
slider.graphics.drawCircle(xPos,yPos, 10);
slider.graphics.endFill();
addChild(slider);
slider.addEventListener(MouseEvent.MOUSE_DOWN, dragSlider);
stage.addEventListener(MouseEvent.MOUSE_UP, stopSlider);
boundary = new Rectangle(-100,0,200,0);
}
/*
dragSlider runs when the use holds the mouse button down. A
startDrag method is used on our sprite where we specify boundary
as our dragging limits. A new event handler designed
to change the mouse volume is subsequenlty called per frame, where
the slider.x property determines volume.
*/
public function dragSlider(event:MouseEvent):void
{
slider.startDrag(false,boundary);
slider.removeEventListener(MouseEvent.CLICK, dragSlider);
slider.addEventListener(Event.ENTER_FRAME, changeVolume);
}
/*
Stops dragging and removes the event listener to save on space. Again,
volume will be based on the sliders current x position, which is
constantly being recalculated per frame because we used an
ENTER_FRAME event.
*/
public function stopSlider(event:MouseEvent):void
{
slider.stopDrag();
slider.removeEventListener(MouseEvent.MOUSE_UP, stopSlider);
}
/*
This function is constantly recalculating the vol variable
based on the sliders x position, relative to the length of
our rectangle. Creates a decimal range from 0 to 1, where 1
represents 100% volume and 0 represents mute. Anything exceeding
100% causes distortion.
*/
public function changeVolume(event:Event):void
{
vol = .5 + Math.round(slider.x) / 200;
channel.soundTransform = new SoundTransform(vol);
}
}
}
this as file i use as "volumecontrol" 's class, wich is a blank fla. with only one blank frame. by itself it works perfect :S
and this is everything that shows on the output panel, after debugin permited is checked:
" TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Volume() "
please, enlighten me x_x
You'll have to do some tracing to try to locate which object is being determined as MIA in your Volume class code. The 1009 error indicates that something being targeted by your code does not exist when that code executes. o if the error message is not indicating a line number for you, then you'll have to gradually trace your way thru the functions in the class to see when the error occurs.
but i dont understand if it's in the Volume class document's code the problem, why does it play perfect ?
it only gives me a problem when i try to load it to the other stage
how do i do some tracing to locate wich object is determined as MIA in the code?
how would you load the volumecontrol swf that has the Volume class on to the index stage?
would you use the UILoader like i am using ?
"but i dont understand if it's in the Volume class document's code the problem, why does it play perfect ?
it only gives me a problem when i try to load it to the other stage"
The error is pointing to the Volume class, and since that appears to be the only thing with any length of code... there's your suspect. There may be something in the code that is stage dependent, and you've just switched that point of reference.
"how do i do some tracing to locate wich object is determined as MIA in the code?"
This will be a good exercise for you if you have little familiarity with troubleshooting with the trace function. You place a trace in each function just to see if you can isolate which function is failing. You could try putting a trace at the start and end within each function and see if any one of them fails to produce both traces or if the error message occurs between them. Once you have the function narrowed down, you can go line by line tracing any object the code is trying to target. If a trace produces a null or an undefined value, then you've likely found the problem.
"how would you load the volumecontrol swf that has the Volume class on to the index stage?
would you use the UILoader like i am using ?"
I would use the Loader class... I avoid using components as much as possible. But that has no bearing on your problem.
North America
Europe, Middle East and Africa
Asia Pacific