flash actionscript:
HI
The problem is that I cannot get the value from class and then used it in
textfield.
I'm getting different values from XML file and one of them is name of current
song.
It works fine when I trace it inside of for loop which is inside xml.onLoad
function
but when I want to trace it outside of that xml.onLoad function it traces me
undefined and the same result is in any other function...
I don't know where is the problem. I'm sure it's my fault because this is my
first class and I don't know much of it right now.
If you have any idea what am I doing wrong please tell me.
Thanks in advance
This is the current code of that class:
import com.mosesSupposes.fuse.*;
//
class com.mloncaric.soundPlayer {
//
var xml:XML;
var urls:Array;
var band_txt:Array;
var song_txt:Array;
var album_txt:Array;
var _sound:Sound;
var _index:Number = 0;
var pos:Number;
var vol:Number;
var _loaded:Number;
//
var isPlaying:Boolean = false;
//
function soundPlayer() {
ZigoEngine.register(Fuse, PennerEasing);
trace(_index);
}
//
function loadXML(targetXML:String) {
var root:Object = this;
xml = new XML();
urls = new Array();
band_txt = new Array();
song_txt = new Array();
album_txt = new Array();
_sound = new Sound();
pos = new Number();
vol = new Number();
//_loaded = new Number();
//
xml.ignoreWhite = true;
//
xml.onLoad = function(success:Boolean) {
if (success) {
var temp:Array = this.firstChild.childNodes;
//
for (var i:Number = 0; i<temp.length; i++) {
root.band_txt.push(temp[i].attributes._band_txt);
root.song_txt.push(temp[i].attributes._song_txt);
root.album_txt.push(temp[i].attributes._album_txt);
root.urls.push(temp[i].attributes._src);
//trace(root.song_txt[i]);//undefined
}
}
};
//
xml.load(targetXML);
}
//
function playSong(mc1:MovieClip, mc2:MovieClip) {
if (isPlaying == false) {
_sound.start(0, 100);
_sound.loadSound(urls[_index], true);
isPlaying = true;
playpause(mc1, mc2, isPlaying);
} else {
_sound.start(0, 100);
_sound.loadSound(urls[_index], true);
isPlaying = false;
playpause(mc1, mc2, isPlaying);
}
}
function pauseSong(mc1:MovieClip, mc2:MovieClip) {
if (isPlaying == true) {
pos = _sound.position/1000;
_sound.stop();
isPlaying = false;
} else {
_sound.start(pos, 100);
isPlaying = true;
}
}
function stopSong(mc1:MovieClip, mc2:MovieClip) {
pos = 0;
_sound.stop();
if (isPlaying) {
isPlaying = false;
playpause(mc1, mc2, isPlaying);
} else {
playpause(mc1, mc2, isPlaying);
}
}
function nextSong() {
if (_index<urls.length-1) {
_index++;
pos = 0;
//
if (isPlaying == true) {
_sound.start(pos, 100);
_sound.loadSound(urls[_index], true);
}
} else {
_index = 0;
//
if (isPlaying == true) {
_sound.start(pos, 100);
_sound.loadSound(urls[_index], true);
}
}
}
function prevSong() {
if (_index>0) {
_index--;
pos = 0;
//
if (isPlaying == true) {
_sound.start(pos, 100);
_sound.loadSound(urls[_index], true);
}
} else {
_index = urls.length-1;
//
if (isPlaying == true) {
_sound.start(pos, 100);
_sound.loadSound(urls[_index], true);
}
}
}
function soundVolume() {
_sound.setVolume(vol);
}
function playpause(mc1:MovieClip, mc2:MovieClip, xy:Boolean) {
if (xy == true) {
mc1._visible = false;
mc2._visible = true;
} else {
mc2._visible = false;
mc1._visible = true;
}
}
function RollOver(target_mc:MovieClip) {
_animation(target_mc, 100);
}
function RollOut(target_mc:MovieClip) {
_animation(target_mc, 50);
}
function _animation(target_mc:MovieClip, alpha:Number) {
var f:Fuse = new Fuse();
//
f.push({target:target_mc, _alpha:alpha, seconds:0.5,
ease:"easeOutQuad"});
f.start();
}
function progressStatus(pBar:MovieClip, scrub_mc:MovieClip,
posBar:MovieClip, ozadje_mc:MovieClip) {
_loaded = _sound.getBytesLoaded()/_sound.getBytesTotal();
pBar._width = _loaded*ozadje_mc._width;
scrub_mc._x = (_sound.position/_sound.duration)*pBar._width;
posBar._width = scrub_mc._x;
//trace(song_txt[_index]);//undefined
}
}