I'm really new to this, so, I'm really sorry if there is some obvious solution that I've somehow missed, but oh well...
I am in the process of making a game, and I was trying to make a character selection menu. Each character would have a unique version of the same song (with the same bps) so that when you were "hovering over" one of the choices, the character's song would play and the other ones would be muted (Not paused or stopped, so as not to lose the synchronisation between all the versions of the song)...
Right now, I was trying to program this for only one of the songs, and then, repeat the method for the other ones once I figured it out.
So...
What am I doing wrong?
Here's the code:
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.media.SoundTransform;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
public class MainThing extends MovieClip {
private var soulcounting: Number = 1;
private var Muting: Boolean = false;
private var snd:Sound = new Sound();
public function MainThing() {
snd.load(new URLRequest("SOUL1.mp3"));
stage.addEventListener(Event.ENTER_FRAME, FrameHandler);
}
private function FrameHandler(event: Event): void {
if (Object(root).currentFrame == 2) {
var channel:SoundChannel = snd.play(0,1);
channel.soundTransform = new SoundTransform(1,0);
/*the soulcounting number is determined by a keyboard function...
I didn't deem it necessary to be included in here,
as I don't think it is part of the problem.*/
if (soulcounting == 1) {
Object(root).SOULS.gotoAndStop(1);
Muting = false;
}
if (soulcounting == 2) {
Object(root).SOULS.gotoAndStop(2);
Muting = true;
}
if (soulcounting == 3) {
Object(root).SOULS.gotoAndStop(3);
Muting = true;
}
if (soulcounting == 4) {
Object(root).SOULS.gotoAndStop(4);
Muting = true;
}
if (soulcounting == 5) {
Object(root).SOULS.gotoAndStop(5);
Muting = true;
}
if (soulcounting == 6) {
Object(root).SOULS.gotoAndStop(6);
Muting = true;
}
if(Muting){
setVolume(channel);
}
if(!Muting){
setVolume(channel, 1);
}
}
private function setVolume (Soundchannel:SoundChannel, volume:Number=0) {
var trans:SoundTransform = Soundchannel.soundTransform;
trans.volume = volume;
Soundchannel.soundTransform = trans;
}
}
}
(If I try to preview the swf, everything works fine until I get to the second frame, in which the Output starts repeating TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MainThing/FrameHandler())
TypeError #1009 seems to be a very common mistake around here, but what I have read hasn't really helped me with this problem... Sorry if there was already a solution in here, and I just didn't search enough...
Thanks in advance!
Object(root)supposed to mean? If it's some MovieClip on the stage why not give that MC an instance name then in code just target it withif (myMCName.currentFrame == 2)? - VC.Oneif (contMC.currentFrame == 2)etc... - VC.OneObject(root).contMCas I'm working from a .as file. Unless I add a link to the MovieClip, but that just makes it more complicated as I would have to use theaddChildfunction... I didn't know about not using multiple frames in stage (shows how experienced I am), does it cause performance issues? - Mitsuki MK KazenMainThingput codebox.x += 100.. test by ctrl+shift+enter... did the box move to a different position than was put on stage? - VC.One