Copy link to clipboard
Copied
Hi,
I am creating an animation for a touch screen with several sound sliders that control sound volume.
I is all working fine except I am getting this error for all the sliders I created
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at SinfoniasV13_3_2018530_fla::MainTimeline/onEnterFrame12()[SinfoniasV13_3_2018530_fla.MainTimeline::frame811:116]
[UnloadSWF] SinfoniasV13.3.2018530.swf
this is the code I used to control the volume:
var sliderValue:uint = (mypista1.botao1.x)/100;
var gain:caga = new caga();
var trans:SoundTransform;
trans = new SoundTransform(1, 0);
var channel:SoundChannel = gain.play(0, 100, trans);
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void
{
trans.volume =mypista1.botao1.x *0.1;
channel.soundTransform = trans; // or SoundMixer.soundTransform = trans;
}
function onPlaybackComplete(event:Event):void
{
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
This is the bit of code giving the error although all working fine
{
trans.volume =mypista1.botao1.x *0.1;
channel.soundTransform = trans; // or SoundMixer.soundTransform = trans;
}
Thank you all in advance
Best
Ana
Copy link to clipboard
Copied
line 116, frame 811 is trying to reference an object that doesn't exist.
if that's not enough help, what line is that?
Copy link to clipboard
Copied
Hi, thank you for the answer.
I had already identified the line, sorry I didn’t mention that at the beginning.
That line correspond to:
trans.volume=mypista1.botão1.x *0.1
I can’t fint what’s wrong whit it.
mypista1 is the name I gave to the symbol that has the slider and the volume button (botao1).
the error only appears when I publish it.
thanks again
best
Ana
Copy link to clipboard
Copied
what's:
trace(trans);
trace(mypista1);
trace(mypista1.bataol)
prior to that line of code show?
Copy link to clipboard
Copied
Sorry, I don’t understand your question
Copy link to clipboard
Copied
Ok, I understood now...
Copy link to clipboard
Copied
Prior to that line of code I don t have any code in that frame.
I have a symbol (mypista1) that works as a volume slider, and inside it, two symbols the knob (botao1) and the slider guide (pista1) with the code for the knob movement.
The trans was originally in the code that I got from a tutorial ...
Copy link to clipboard
Copied
add those 3 trace statements prior to the problematic line of code.
what's the output panel show?
Copy link to clipboard
Copied
[object SoundTransform]
[object mypista_31]
undefined
this is what the panel shows, like a million times ...
Copy link to clipboard
Copied
when your code executes, there's a mypista1 object, but not a mypista1.bataol.
Copy link to clipboard
Copied
Sorry about the dumb question... but...
How do I solve it??
There is a mypista1 object and inside it there is the botao1 object and the pista1 object...
Copy link to clipboard
Copied
what main timeline frame contains mypista1?
what mypista1 frame contains botao1?
is botao1 part of a tween and is it ever removed from mypista1's timeline?
Copy link to clipboard
Copied
what main timeline frame contains mypista1?
744
what mypista1 frame contains botao1?
1
is botao1 part of a tween and is it ever removed from mypista1's timeline?
No
I can explain you a bit better the project if it helps:
I have several volume slides (mypista1, mypista2, etc) in the same frame in timeline.
The knop (botao1) moves in the balk (pista1) in the frame 1 of mypista with this code:
var knobWidth:Number = botao1.width;
var trackWidth:Number = pista1.width;
var trackX:Number = pista1.x;
var boundWidth = trackWidth - knobWidth;
var boundsRect:Rectangle = new Rectangle(trackX, 0, boundWidth, 0);
//beginpositie sliderKnob
botao1.x =270;
//Enable drag
botao1.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
function startDragging(event:MouseEvent) {
botao1.startDrag(false, boundsRect);
}
//Stop drag
botao1.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
//knop.addEventListener(MouseEvent.ROLL_OUT, stopDragging);
function stopDragging(event:MouseEvent) {
botao1.stopDrag();
}
//onRealeaseOutside
stage.addEventListener(MouseEvent.MOUSE_UP,upStage);
function upStage(e:MouseEvent):void {
stopDrag();
}
Each slide (mypista1) controls a different volume whith this code:
var sliderValue:uint = (mypista1.botao1.x)/100;
var gain:caga = new caga();
var trans:SoundTransform;
trans = new SoundTransform(1, 0);
var channel:SoundChannel = gain.play(0, 100, trans);
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void
{
trans.volume =mypista1.botao1.x *0.1;
channel.soundTransform = trans; // or SoundMixer.soundTransform = trans;
}
function onPlaybackComplete(event:Event):void
{
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
All works fine in terms of sound. But when I test it the error appear after pressing a go back button (gotoAndStop)
Thank you sooooo much for trying to help me ...
Copy link to clipboard
Copied
do you see the error every time the frame that contains that code displays?
Copy link to clipboard
Copied
No, Just when I press the go back button...
Copy link to clipboard
Copied
i don't see any way to determine the problem via a forum. imo someone will need to download and fix your fla.
but maybe someone else can figure it out.
Copy link to clipboard
Copied
Thank you very much any way... I'll keep trying to solve the problem, or try to find a different code to play the sounds and changing volumes.
Best regards
AB
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now