LuisPedro
01-19-2008, 10:43 AM
He all!!
I'm trying to use value variables throw public functions in the same class.
Is there any possible to do it?
I'll explain:
Imagine we have a class name Mp3Player that plays some mp3 file and get is ID3 songName:
In that class we have the package:
package Mp3Player{
import flash.media.Sound;
import flash.media.SoundLoaderContext;
import flash.media.SoundChannel;
import flash.media.ID3Info;
import flash.net.URLRequest;
import flash.events.Event;
public class Mp3Player {
private var sound:Sound;
private var req:URLRequest;
private var context:SoundLoaderContext;
private var channel:SoundChannel;
private var id3:ID3Info;
private var nomeMusica:String;
Then we have the public class to load and play the mp3 file passed using argument "file":
public function tocarMusica(file) {
sound=new Sound ;
req=new URLRequest(file);
context=new SoundLoaderContext(8000,true);
sound.load(req,context);
channel=sound.play();
sound.addEventListener(Event.ID3,setNome);
}
After we load and start play the mp3 file, we whant to get the ID3 songName and save it in the "nomeMusica" variable:
public function setNome(event:Event) {
id3=event.target.id3;
nomeMusica=id3.songName;
trace("Nome: "+nomeMusica);
}
Now the problem is...How can i trace(nomeMusica) outside the "public function setNome(event:Event)"?
Or in other words:
In the FLA file i can call to play the mp3 file like this:
var musica = new Mp3Player();
musica.tocarMusica("song.mp3");
And how can i call the ID3 songName using sometinh like:
musica.getName();
Sorry my english and i hope you can help me in a simple way.
:)
I'm trying to use value variables throw public functions in the same class.
Is there any possible to do it?
I'll explain:
Imagine we have a class name Mp3Player that plays some mp3 file and get is ID3 songName:
In that class we have the package:
package Mp3Player{
import flash.media.Sound;
import flash.media.SoundLoaderContext;
import flash.media.SoundChannel;
import flash.media.ID3Info;
import flash.net.URLRequest;
import flash.events.Event;
public class Mp3Player {
private var sound:Sound;
private var req:URLRequest;
private var context:SoundLoaderContext;
private var channel:SoundChannel;
private var id3:ID3Info;
private var nomeMusica:String;
Then we have the public class to load and play the mp3 file passed using argument "file":
public function tocarMusica(file) {
sound=new Sound ;
req=new URLRequest(file);
context=new SoundLoaderContext(8000,true);
sound.load(req,context);
channel=sound.play();
sound.addEventListener(Event.ID3,setNome);
}
After we load and start play the mp3 file, we whant to get the ID3 songName and save it in the "nomeMusica" variable:
public function setNome(event:Event) {
id3=event.target.id3;
nomeMusica=id3.songName;
trace("Nome: "+nomeMusica);
}
Now the problem is...How can i trace(nomeMusica) outside the "public function setNome(event:Event)"?
Or in other words:
In the FLA file i can call to play the mp3 file like this:
var musica = new Mp3Player();
musica.tocarMusica("song.mp3");
And how can i call the ID3 songName using sometinh like:
musica.getName();
Sorry my english and i hope you can help me in a simple way.
:)