Elementxo
Elementxo

Reputation: 27

AS3 Error 1195:

I am getting the following errors:

C:\Users\Admin\Desktop\Final Project\Main.as, Line 80, Column 14 1195: Attempted access of inaccessible method setTrackData through a reference with static type LoadSND.

Relevant code

package {

import flash.display.MovieClip;
import flash.text.TextField;
import flash.display.SimpleButton;
import flash.utils.Dictionary;
import flash.text.TextFormat;
import flash.net.*;
import flash.events.*;
import fl.controls.*;
import flash.media.*;
import fl.events.ComponentEvent;
import fl.managers.StyleManager;
import fl.data.DataProvider;
import fl.data.SimpleCollectionItem;
import fl.managers.StyleManager;
import fl.events.ComponentEvent;
import flash.events.Event;
import flash.net.SharedObject;
import LoadSWF;
import GameButton;
import LoadSND;


public class Main extends MovieClip {

    //Declare variables
    private var componentFmt: TextFormat;
    private var radioBtnFmt: TextFormat;
    private var playerData: Object;
    private var savedGameData: SharedObject;
    // Pop-up Variables     
    private var popupFile: LoadSWF;
    private var swfPath: String;
    private var swfFile: LoadSWF;



    //Sound Variables
    private var MAX_TRAX: int = 7;
    private var MAX_SFX: int = 9;
    private var sndPath: String;
    private var sndTrack: LoadSND;
    private var isMuted: Boolean;
    private var canRepeat: Boolean;
    private var sndVolume: Number;
    private var sndChannel: SoundChannel;



    public function Main() {
        // constructor code
        this.savedGameData = SharedObject.getLocal("savedPlayerData");
        this.setComponents();
        this.setPlayerData();
        swfPath = "";
        sndPath = "musicSFX/Fury.mp3"; //default track
        isMuted = false;
        sndTrack = new LoadSND(sndPath, canRepeat);

    }


    /********************************************************
    Load SND Functions***************************************
    ********************************************************/
    private function setSound(evt: Event): void {
        // Process COMBO BOX changes 
        if (musicCombo.selectedItem.data == "none") {
            // no music is required so stop sound playing 
            SoundMixer.stopAll();
        } else {
            // otherwise load in the selected music 
            sndPath = "musicSFX/" + musicCombo.selectedItem.data;
            sndTrack.setTrackData(sndPath, canRepeat);
        }
    }

    private function setSlider(evt: Event): void {
        // identify the button clicked 
        var mySlider: Object = (evt.target);
        // adjusting to volume of the music channel to slider value 
        sndTrack.setVolumeLevel(mySlider.value);
    }

    private function setVolumeLevel(myVolume: Number): void {
        // change the volume when slider changed 
        sndVolume = myVolume;
        sndChannel.soundTransform = new SoundTransform(sndVolume, 0);
    }

Also: the LoadSND Class

package {
import flash.events.*;
import flash.media.*;
import flash.net.URLRequest;
import flash.display.MovieClip;


public class LoadSND extends MovieClip {

    //declare variables
    private var sndTrack: Sound;
    private var sndChannel: SoundChannel;
    private var sndVolume: Number;
    private var newTrack: String;
    private var canRepeat: Boolean;

    public function LoadSND(myTrack: String, myRepeat: Boolean = true) {
        // constructor code
        // set a default volume and track 
        sndVolume = 0.5;
        setTrackData(myTrack, myRepeat);
    }


    private function loadSound(): void {
        // first stop all old sounds playing 
        SoundMixer.stopAll();
        // create a new sound for the track and a new sound channel 
        sndTrack = new Sound();
        sndChannel = new SoundChannel();
        // load the required sound
        sndTrack.load(new URLRequest(newTrack));
        // when loaded – play it;
        sndTrack.addEventListener(Event.COMPLETE, soundLoaded);
    }

    private function soundLoaded(evt: Event): void {
        // finished with this listener so remove it 
        //sndTrack.removeEventListener(Event.COMPLETE, soundLoaded);
        // call the play sound function 
        playSound();

    }

    private function playSound(): void {
        // assign music to the musicChannel and play it 
        sndChannel = sndTrack.play();
        // setting the volume control property to the sound channel 
        sndChannel.soundTransform = new SoundTransform(sndVolume, 0);
        // but add this one to make repeats 
        sndChannel.addEventListener(Event.SOUND_COMPLETE, playAgain);
    }

    private function playAgain(evt: Event): void {
        // remove this listener and repeat playSound() 
        sndChannel.removeEventListener(Event.SOUND_COMPLETE, playAgain);
        playSound();
    }

    private function setTrackData(myTrack: String, myRepeat: Boolean): void {
        // update the new track information 
        newTrack = myTrack;
        canRepeat = myRepeat;
        // and load it 
        loadSound();

    }

    private function setVolumeLevel(myVolume: Number): void {
        // change the volume when slider changed 
        sndVolume = myVolume;
        sndChannel.soundTransform = new SoundTransform(sndVolume, 0);
    }




} //end class

} //end package

Appreciate all the help :) thanks

Upvotes: 1

Views: 415

Answers (1)

Mehdi Golzadeh
Mehdi Golzadeh

Reputation: 2583

Your setTrackData function in LoadSND class is private. you need to change type of the function to public so that you have access this function from the main class.

so change you function like this

public function setTrackData(myTrack: String, myRepeat: Boolean): void {
        // update the new track information 
        newTrack = myTrack;
        canRepeat = myRepeat;
        // and load it 
        loadSound();

}

Upvotes: 2

Related Questions