Показать сообщение отдельно
Старый 07.08.2012, 15:42
barcelona92 вне форума Посмотреть профиль Отправить личное сообщение для barcelona92 Найти все сообщения от barcelona92
  № 9  
Ответить с цитированием
barcelona92

Регистрация: Aug 2012
Сообщений: 26
Код AS3:
package  {
 
	import flash.media.Sound;
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.net.*;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import flash.media.SoundChannel;
	import flash.media.SoundTransform;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.events.MouseEvent;
	import flash.events.*;
	import flash.utils.*;
    import flash.events.IOErrorEvent;
 
 
	public class Preference extends MovieClip {
		[Embed(source = "pimp.png")] private var pimpImage:Class;
		[Embed(source = "back.png")] private var backImage:Class;
		public var _eventTextField:TextField;
		public var _sound:Sound;
		public var _soundChannel:SoundChannel;
		public var _soundTransform:SoundTransform;
		public static var sound = new GameSound();
		private var _gameSound:GameSound;
		private var _backgroundMusic:Boolean = true;
		public function set backgroundMusic(value:Boolean):void {
	_backgroundMusic = value;
	if(_backgroundMusic) {
		_gameSound.volume = 1;
	} else {
		_gameSound.volume = 0;
	}
}
		public function Preference() {
 
				if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
 
 
 
 
			// constructor code
			//Go_Home_Preference
			//Go_Info_Preference
			//Go_App_Preference
			Game.GG =false;
 
			//Go_Home_Preference.buttonMode = true;
			//Go_Home_Preference.mouseChildren = false;
			Go_Home_Preference.addEventListener(MouseEvent.CLICK,PlayHome);	
 
			//Go_Info_Preference.buttonMode = true;
			//Go_Info_Preference.mouseChildren = false;
			Go_Info_Preference.addEventListener(MouseEvent.CLICK,PlayInfo);	
 
			//Go_App_Preference.buttonMode = true;
			//Go_App_Preference.mouseChildren = false;
			Go_App_Preference.addEventListener(MouseEvent.CLICK,PlayApp);	
 
 
			//Go_To_Preference.buttonMode = true;
			//Go_To_Preference.mouseChildren = false;
			Go_To_Preference.addEventListener(MouseEvent.CLICK,PlayPreference);	
 
			go_pref_stars.addEventListener(MouseEvent.CLICK,PlayStars);	
 
			User_Name_Preference.text = String(Main_Game.User);			
		}
 
 
		public function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			_eventTextField = new TextField();
			addChild(_eventTextField);
			_eventTextField.defaultTextFormat = new TextFormat("Arial", 18, 0xFFFFFF, true);
			_eventTextField.x = 700;
			_eventTextField.y = 300;
 
 
			var switcher:Switcher = new Switcher(new backImage(), new pimpImage(), new Rectangle(2, 2, 69, 0));
			switcher.addEventListener(Switcher.ON, handlerSoundON);
			switcher.addEventListener(Switcher.OFF, handlerSoundOFF);
			switcher.setState(Switcher.ON);
			this.addChild(switcher);
			switcher.x = 700;
			switcher.y = 400;
		}
 
		private function handlerSoundON(event:Event):void 
		{
			_eventTextField.text = "Sound ON";
			backgroundMusic = true;
		}
 
		private function handlerSoundOFF(event:Event):void 
		{
			_eventTextField.text = "Sound OFF";
			backgroundMusic = false;
		}
 
 
		public function PlayInfo(e:MouseEvent):void{
 
			Main_Game.screens.switchTo("Info");
 
			}
		public function PlayHome(e:MouseEvent):void{
 
			Main_Game.screens.switchTo("Start");
 
			}
		public function PlayApp(e:MouseEvent):void{
 
			Main_Game.screens.switchTo("App");
 
			}
		public function PlayPreference(e:MouseEvent):void{
 
			Main_Game.screens.switchTo("Configuration");
			}
 
		public function PlayStars(e:MouseEvent):void{
 
			Main_Game.screens.switchTo("all_stars");
 
		}
 
			}
 
}
когда перехожу на Preference дает такую ошибку

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Preference/set backgroundMusic()
at Preference/handlerSoundON()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at Switcher/setPimpPosition()
at Switcher/init()
at flash.display:isplayObjectContainer/addChild()
at Preference/init()
at flash.display:isplayObjectContainer/addChild()
at ScreenHand/switchTo()
at Start/PlayPreference()


вот мой преференс,там вставлен свитчер а soundGame это я решил создать новый и вставил ваш код,
я уже заколебался,надеюсь это последняя ошибка



а,кстати,такой вопрос
Я же могу кинуть музыку просто на сцену и поставить Loop только как мне обратиться чтоб vol уменьшить только этого звука?или это невозможно?


Последний раз редактировалось barcelona92; 07.08.2012 в 16:00.