-1

ボタンがクリックされたときの音の音量を調整しようとしています。

行 86 1120: 未定義のプロパティへのアクセスadjustVolume

行 91 1120: 未定義のプロパティへのアクセスadjustVolume

ここにコードがあります

package 
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import fl.controls.CheckBox;
import fl.controls.Slider;
import flash.media.SoundTransform;

public class Track extends MovieClip
{
    public var trackSound:Sound;
    public var theChannel:SoundChannel;
    public var songName:String;
    public var currentStep:Number = 0;
    public var checkboxArray:Array;
    //public var adjustVolume:SoundTransform = new SoundTransform();
    /*adjustVolume.volume = 1;
    theChannel.soundTransform = adjustVolume;*/


    // onoff array of 16 false booleans
    public function Track()
    {
        // constructor code

        var adjustVolume:SoundTransform = new SoundTransform();
        adjustVolume.volume = 1;
        theChannel.soundTransform = adjustVolume;


        //trace( this.parent.name+"."+ this.name + " track created "  );
        singlePlay.addEventListener(flash.events.MouseEvent.CLICK, handlePlayClick);

        trackVolDown.addEventListener(flash.events.MouseEvent.CLICK, trackVolumeHandler);
        trackVolUp.addEventListener(flash.events.MouseEvent.CLICK, trackVolumeHandler);

        c1.addEventListener(flash.events.MouseEvent.CLICK, handleStepClick);
        c2.addEventListener(flash.events.MouseEvent.CLICK, handleStepClick);
        c3.addEventListener(flash.events.MouseEvent.CLICK, handleStepClick);
        c4.addEventListener(flash.events.MouseEvent.CLICK, handleStepClick);
        c5.addEventListener(flash.events.MouseEvent.CLICK, handleStepClick);
        c6.addEventListener(flash.events.MouseEvent.CLICK, handleStepClick);
        c7.addEventListener(flash.events.MouseEvent.CLICK, handleStepClick);
        c8.addEventListener(flash.events.MouseEvent.CLICK, handleStepClick);
        c9.addEventListener(flash.events.MouseEvent.CLICK, handleStepClick);
        c10.addEventListener(flash.events.MouseEvent.CLICK, handleStepClick);
        c11.addEventListener(flash.events.MouseEvent.CLICK, handleStepClick);
        c12.addEventListener(flash.events.MouseEvent.CLICK, handleStepClick);
        c13.addEventListener(flash.events.MouseEvent.CLICK, handleStepClick);
        c14.addEventListener(flash.events.MouseEvent.CLICK, handleStepClick);
        c15.addEventListener(flash.events.MouseEvent.CLICK, handleStepClick);
        c16.addEventListener(flash.events.MouseEvent.CLICK, handleStepClick);

        checkboxArray = new Array(c1,c2, c3, c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16);
        //trace (checkboxArray[0].selected);            
    }
    private function handlePlayClick(e:Event):void
    {
        //trace( this.parent.name+"."+ this.name +" Play clicked");
        this.playSound();
    }       
    public function setSoundName(theName:String)
    {
        this.songName = theName;
        trackSound = new Sound();
        var req:URLRequest = new URLRequest(this.songName);
        trackSound.addEventListener(Event.COMPLETE, onSoundLoaded);
        trackSound.load(req);
    }

    private function onSoundLoaded(e:Event):void
    {
        //trace(this.songName + " loaded into sequencer");
    }

    public function playSound( currentStep:Number = -1)
    {

        if (currentStep == -1)
        {
            theChannel = trackSound.play();
            theChannel.soundTransform = adjustVolume;//error here
        }
        else if (this.checkboxArray[currentStep].selected)
        {
            theChannel = trackSound.play();
            theChannel.soundTransform = adjustVolume;// and error here
        }
    }
    public function stopSound():void
    {
        theChannel.stop();
    }

    private function handleStepClick(e:Event):void
    {
        trace( this.name+'.'+(e.target as CheckBox).name);

    }   
    private function trackVolumeHandler(e:Event):void
    {
        //trace( this.parent.name+"."+ this.name +" Play clicked");
        this.soundTransform;
    }       

}
}

誰か助けてくれませんか?

4

2 に答える 2

0

tl;dr

コンストラクターを使用してフィールドを初期化します。

詳細

次の行を置き換えます。

var adjustVolume:SoundTransform = new SoundTransform();
adjustVolume.volume = 1;
theChannel.soundTransform = adjustVolume;

に:

private var adjustVolume:SoundTransform;
public function Track()
{
    adjustVolume = new SoundTransform();
    adjustVolume.volume = 1;
    theChannel.soundTransform = adjustVolume;
}
于 2012-11-23T14:13:36.023 に答える
0

交換した

public var theChannel:SoundChannel;

public var theChannel:SoundChannel = new SoundChannel;

そしてそれは今動作します

于 2012-11-23T15:04:36.383 に答える