Comunidad de diseño web y desarrollo en internet online

Problema con llamada a funciones

Citar            
MensajeEscrito el 09 Nov 2009 02:22 pm
Buenas a todos, les comento rápidamente...

Tengo una clase para reproducir audio, la misma tiene 2 funciones públicas llamadas playSong y pauseSong.

Desde el timeline de un .fla en un llamado a una función creo una variable e inicializo la clase del audio de esta manera:

Código ActionScript :

var musica_perfil:my_sound = new my_sound("music.mp3");


Luego en otra función de este mismo timeline quiero llamar a las funciones playSong y pauseSong de la clase my_sound de la siguiente manera:

Código ActionScript :

musica_perfil.pauseSong();
musica_perfil.playSong();


Pero me tirá un error diciendome que musica_perfil es una propiedad undefined...

¿Alguna idea de que estoy haciendo mal? Estoy seguro que es una pavada pero no puedo darme cuenta...

Gracias!

Javier

Por Maggical

11 de clabLevel



 

firefox
Citar            
MensajeEscrito el 09 Nov 2009 03:10 pm
Supongo que my_sound es una clase que extiende de Sound cierto?

Has hecho el import correspondiente para que te lo detecte?

Las funciones pauseSong y playSong son publicas no?

Por ur!

256 de clabLevel



 

Barcelona

chrome
Citar            
MensajeEscrito el 09 Nov 2009 03:15 pm
Si, te pego el código de la clase para que veas:

Código ActionScript :

package com.jespana {
   ///
   import flash.display.Sprite;
   import flash.events.*;
   import flash.media.Sound;
   import flash.media.SoundChannel;  
   import flash.media.SoundTransform;
   import flash.media.SoundMixer;
   import flash.net.URLRequest;
   import flash.utils.Timer;
   import flash.utils.ByteArray;  

   public class my_sound extends Sprite {
      ///
      // VARIABLES
      ///
      private var url:String;
      private var song:SoundChannel;
      private var soundFactory:Sound;
      private var FourierTransform:Boolean = false;
      private var arrayMixer:ByteArray = new ByteArray();
      private var pan:int = 0;
      private var porcentLoad:Number = 0; 
      private var pausePoint:Number = 0.00;

      /*----------------------- INIT -----------------------*/
      /*----------------------- INIT -----------------------*/
      /*----------------------- INIT -----------------------*/
      /*----------------------- INIT -----------------------*/
      /*----------------------- INIT -----------------------*/
      /*----------------------- INIT -----------------------*/

      public function my_sound(mp3:String):void {
         ///
         url = mp3;
         cargarSong();
      }

      /*----------------------- UTILS -----------------------*/
      /*----------------------- UTILS -----------------------*/
      /*----------------------- UTILS -----------------------*/
      /*----------------------- UTILS -----------------------*/
      /*----------------------- UTILS -----------------------*/
      /*----------------------- UTILS -----------------------*/

      public function cargarSong():void {
         ///
         SoundMixer.stopAll();
         soundFactory = new Sound();
         var request:URLRequest = new URLRequest(url);
         ///
         soundFactory.addEventListener(Event.COMPLETE, completeHandler);
         soundFactory.addEventListener(ProgressEvent.PROGRESS, progressHandler);
         soundFactory.load(request);
      }

      public function playSong():void {
         ///
         song = soundFactory.play(pausePoint);
      }

      public function pauseSong():void {
         ///
         pausePoint = song.position;
         song.stop();
      }

      public function get Mixer():ByteArray {
         ///
         SoundMixer.computeSpectrum(arrayMixer, FourierTransform);
         return arrayMixer;
      }

      public function set Fourier(valor:Boolean):void {
         ///
         this.FourierTransform = valor;
      }

      public function get Fourier():Boolean {
         ///
         return FourierTransform;
      }

      /*----------------------- LISTENERS -----------------------*/
      /*----------------------- LISTENERS -----------------------*/
      /*----------------------- LISTENERS -----------------------*/
      /*----------------------- LISTENERS -----------------------*/
      /*----------------------- LISTENERS -----------------------*/
      /*----------------------- LISTENERS -----------------------*/

      private function completeHandler(event:Event):void {
         ///
         playSong();
      }

      private function progressHandler(event:ProgressEvent):void {
         ///
         porcentLoad = Math.round((event.bytesLoaded*100)/event.bytesTotal);
      }
   }
}


Y en el timeline tengo:

Código ActionScript :

import com.jespana.my_sound;

function activarPerfilDerecha():void {
   ///
   var musica_perfil:epika_sound = new epika_sound("music.mp3");
}

function clickMusica():void {
   ///
   if(perfil_mc.derecha_mc.music_mc.currentFrame == 1){
      ///
      perfil_mc.derecha_mc.music_mc.gotoAndStop(2);
      perfil_mc.derecha_mc.music_mc.lines_mc.gotoAndPlay(37);
      ///
      musica_perfil.pauseSong();
   }
   else{
      ///
      perfil_mc.derecha_mc.music_mc.gotoAndStop(1);
      perfil_mc.derecha_mc.music_mc.lines_mc.gotoAndPlay(46);
      ///
      musica_perfil.playSong();
   }
}


Gracias por la ayuda...

Javier

Por Maggical

11 de clabLevel



 

firefox
Citar            
MensajeEscrito el 09 Nov 2009 03:32 pm
Mmmm...

Aquí supongo que epika_sound es un error y querías poner my_sound no?

Código ActionScript :

var musica_perfil:epika_sound = new epika_sound("music.mp3"); 


por

Código ActionScript :

 var musica_perfil:my_sound = new my_sound("aaa.mp3"); 


De todas formas, de la segunda manera a mi me funciona. He copiado tu clase y he creado un archivo flash as3 vacio, y con esa línea sóla me carga el sonido. Y luego haciendo un musica_perfil.pauseSong me lo para

Por ur!

256 de clabLevel



 

Barcelona

chrome
Citar            
MensajeEscrito el 09 Nov 2009 05:50 pm
No tengo idea entonces porque no me funciona... Es como dices :S

Voy a tratar de reprogramar de nuevo algunas cosas a ver si lo puedo sacar por otro lado, si alguien tiene alguna idea de que esta pasando es bienvenido...

Gracias,

Javier

Por Maggical

11 de clabLevel



 

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.