-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;博士

使用构造函数来初始化您的字段。

细节

替换以下行:

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 回答