Hello,
Having a bit of trouble with some AS3. Any help you can provide would be very appreciated.
Error:
TypeError: Error #1010: A term is undefined and has no properties.
Code:
var soundReq:URLRequest = new URLRequest("audio05.mp3");
var sound:Sound = new Sound();
sound.load(soundReq);
sound.addEventListener(Event.COMPLETE, onComplete);
function onComplete(event:Event):void
{
sound.play();
}
var mySoundChannel:SoundChannel;
var isPlaying:Boolean = false;
var pos:Number = 0;
play_btn.addEventListener(MouseEvent.CLICK, play_);
function play_(event:Event):void
{
if (!isPlaying)
{
mySoundChannel = sound.play(pos);
isPlaying = true;
}
}
pause_btn.addEventListener(MouseEvent.CLICK, pause_);
function pause_(event:Event):void
{
if (isPlaying)
{
pos = mySoundChannel.position;
mySoundChannel.stop();
isPlaying = false;
}
}
stop_btn.addEventListener(MouseEvent.CLICK, stop_);
function stop_(event:Event):void
{
if (mySoundChannel != null)
{
mySoundChannel.stop();
pos = 0;
isPlaying = false;
}
}
var rectangle:Rectangle = new Rectangle(0,0,48,0);
var dragging:Boolean = false;
volume_mc.mySlider_mc.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
function startDragging(event:Event):void
{
volume_mc.mySlider_mc.startDrag(false,rectangle);
dragging = true;
volume_mc.mySlider_mc.addEventListener(Event.ENTER_FRAME, adjustVolume);
}
function adjustVolume(event:Event):void
{
var myVol:Number = volume_mc.mySlider_mc.x / 48;
var mySoundTransform:SoundTransform = new SoundTransform(myVol);
if (mySoundChannel != null)
{
mySoundChannel.soundTransform = mySoundTransform;
}
}
stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
function stopDragging(event:Event):void
{
if (dragging)
{
dragging = false;
volume_mc.mySlider_mc.stopDrag();
}
}
Thank you,
~AMH~
kglad,
As requested, set to permit debugging and received following error.
Error:
TypeError: Error #1010: A term is undefined and has no properties.
at volumeSliderTest3_fla::MainTimeline/volumeSliderTest3_fla::frame1()[v olumeSliderTest3_fla.MainTimeline::frame1:51]
Code:
var soundReq:URLRequest = new URLRequest("audio05.mp3");
var sound:Sound = new Sound();
sound.load(soundReq);
sound.addEventListener(Event.COMPLETE, onComplete);
function onComplete(event:Event):void
{
sound.play();
}
var mySoundChannel:SoundChannel;
var isPlaying:Boolean = false;
var pos:Number = 0;
play_btn.addEventListener(MouseEvent.CLICK, play_);
function play_(event:Event):void
{
if (!isPlaying)
{
mySoundChannel = sound.play(pos);
isPlaying = true;
}
}
pause_btn.addEventListener(MouseEvent.CLICK, pause_);
function pause_(event:Event):void
{
if (isPlaying)
{
pos = mySoundChannel.position;
mySoundChannel.stop();
isPlaying = false;
}
}
stop_btn.addEventListener(MouseEvent.CLICK, stop_);
function stop_(event:Event):void
{
if (mySoundChannel != null)
{
mySoundChannel.stop();
pos = 0;
isPlaying = false;
}
}
var rectangle:Rectangle = new Rectangle(0,0,48,0);
var dragging:Boolean = false;
volume_mc.mySlider_mc.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
function startDragging(event:Event):void
{
volume_mc.mySlider_mc.startDrag(false,rectangle);
dragging = true;
volume_mc.mySlider_mc.addEventListener(Event.ENTER_FRAME, adjustVolume);
}
function adjustVolume(event:Event):void
{
var myVol:Number = volume_mc.mySlider_mc.x / 48;
var mySoundTransform:SoundTransform = new SoundTransform(myVol);
if (mySoundChannel != null)
{
mySoundChannel.soundTransform = mySoundTransform;
}
}
stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
function stopDragging(event:Event):void
{
if (dragging)
{
dragging = false;
volume_mc.mySlider_mc.stopDrag();
}
}
Thank you,
~AMH~
This has reshifted it's way up the priority list soooo...
I added the traced you recommended and received the following error.
volume_mc
instance1
instance2
TypeError: Error #1010: A term is undefined and has no properties.
at volumeSliderTest3_fla::MainTimeline/volumeSliderTest3_fla::frame1()[v olumeSliderTest3_fla.MainTimeline::frame1:79]
Any thoughts?
Thank you!
~AMH~
At this line,
volume_mc.mySlider_mc.addEventListener(MouseEvent.MOUSE_DOWN, startDragging)
add the line:
trace("Volume MC Slider: " + volume_mc.mySlider_mc);
If I'm correct this will come up as "null". Odds are, your slider is not named mySlider_mc or it is perhaps nested in another MovieClip.
North America
Europe, Middle East and Africa
Asia Pacific