Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 3.0 (http://www.flasher.ru/forum/forumdisplay.php?f=83)
-   -   Как обратиться через event к музыке (http://www.flasher.ru/forum/showthread.php?t=202450)

xrapa 17.07.2013 00:29

Как обратиться через event к музыке
 
Нашел как крутить музыку по кругу
Код AS3:

var req:URLRequest = new URLRequest("sounds/clock_ticking.mp3"); 
var s:Sound = new Sound(req);
var ch:SoundChannel = s.play();
ch.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);
 
function onSoundComplete(event:Event):void
{
    trace("Конец воспроизведения")
}

теперь остался вопрос как обратиться через event к песне, тоесть
event...play()

KumoKairo 17.07.2013 00:48

Код AS3:

function onSoundComplete(event:Event):void
{
    var sch:SoundChannel = event.currentTarget as SoundChannel;
    sch.play();
    trace("Я маленькая лошадка");
}


xrapa 17.07.2013 01:14

выдало вот такую ошибку
1061: Обращение к возможно неопределенному методу play через ссылку статического типа flash.media:SoundChannel.

iNils 17.07.2013 03:15

event.currentTarget
event.target

xrapa 17.07.2013 14:34

таже ошибка, метода play() нету у SoundChannel
http://help.adobe.com/ru_RU/FlashPla...ndChannel.html

tsarapkabel 17.07.2013 16:21

Да, target и currentTarget отдадут SoundChannel. Используйте приватные переменные внутри класса.
Код AS3:

package  
{
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.media.Sound;
        import flash.media.SoundChannel;
        import flash.net.URLRequest;
 
        public class NewClass extends Sprite
        {
                private var snd:Sound;
                private var channel:SoundChannel;
 
                public function NewClass()
                {
                        var req:URLRequest = new URLRequest("sounds/clock_ticking.mp3");
                        snd = new Sound(req);
 
                        onSoundComplete(null);
                }
 
                private function onSoundComplete(event:Event):void
                {
                        channel = snd.play();
                        channel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);
                }
 
        }
}



Часовой пояс GMT +4, время: 16:33.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2024, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.