Combobox-> xml->menu : triggering a new object stopping the old etc

Hi

I have to following :

  • a AS3 file with class description for dealing with sound
  • a flash cs3 file for reading out texts : name, product, artists [like id3 tags]
  • the flash cs3 file uses the as3 file for creating a visual effect based on the given mp3
    [this works great].

But since my as3 is not that good at the moment my question is :

  1. How can I populate a xml based combobox in as3 for changing the actual playing mp3.
    The actual triggering starts when creating a new object in var form…

  2. How can I also readout mp3 id3 tags at the start of the song and using them instead of creating longer xml files etc… [so would love only to use a mp3 name and flash cs3 reads out the id3 tags from the mp3 within…]

Code so far [working!!!] cs3/as2:

//SpectrumAnalyzer.as - file
//reads out a mp3 and visualize it in a circle form left/right pan and bass effect
// not my own!

// SpectrumAnalyzer.as
package {
	import flash.display.*;
	import flash.media.*;
	import flash.net.*;
	import flash.utils.ByteArray;
	import flash.events.*;
	public class SpectrumAnalyzer extends Sprite {
		// Settings
		public var lineThickness:Number = 2;
		public var lineColor:Number = 0x993300;
		public var circleSize:Number = 75;
		public var scaleOnBeat:Number = 1.1; // 110%
		public var reactToBeat:Number = 30;
		//
		public var music:Sound = new Sound;
		public var ba:ByteArray = new ByteArray();
		public var __width:uint;
		public var __height:uint;
		function SpectrumAnalyzer(mp3:String, _width:uint, _height:uint) {
			__width = _width;
			__height = _height;
			x = __width/2;
			y = __height/2
			music.load(new URLRequest(mp3));
			music.play(0, 1); // 1 playing one time, 999 endless duhh
			addEventListener(Event.ENTER_FRAME, processSound);
		}
		public function processSound(ev:Event) {
			SoundMixer.computeSpectrum(ba, true, 0);
			graphics.clear();
			graphics.moveTo(0, -circleSize);
			graphics.lineStyle(lineThickness, lineColor);
			var vol:Number = 0;
			for (var i:uint = 0; i <512; i++) {
				var lev:Number = ba.readFloat();
				vol += lev;
				var a:uint = i;
				if (i <256) a += 256;
				if (i == 256) graphics.moveTo(0, -circleSize);
				graphics.lineTo(-Math.sin(i/256*Math.PI)*circleSize*(lev+1), Math.cos(a/256*Math.PI)*circleSize*(lev+1));
			}
			if (vol> reactToBeat) {
				_global.beat = true;
				scaleX = scaleY = scaleOnBeat;
				
			} else {
				_global.beat = false;
				scaleX = scaleY = 1;
				
			}
		}
	}
}

IN flash cs 3 frame 1: as3 :
[2 text fields used for reading out mp3 name and description via flashvar from php file integrated into a html file containing the embed stuff…

// spectrum.fla

import com.SpectrumAnalyzer;
import com.testClass;

//trace(_global.beat);

//reading out the flashvar data and plac ein the 2 fields... demos, demop
root.demos.htmlText = "song: "+root.loaderInfo.parameters.song;
root.demop.htmlText = "product: "+root.loaderInfo.parameters.product;

var link:String = root.loaderInfo.parameters.song;

//here the exctual visualisation starts.... BUT!!  how can I trigger a new SpectrumAnalyzer //object [with null? and then via an xml based combobox based on flashvars to redirect //flash to the right mp3 [maybe also reading then the  id3 tags from mp3]

var visualization:SpectrumAnalyzer = new SpectrumAnalyzer(link, 330, 520);
visualization.x=120;
visualization.y=120;

addChild(visualization);

//de listener
stopme.addEventListener(MouseEvent.CLICK, actie);

//de function actie
function actie(event:MouseEvent):void{
 	processSound().stop();
}
 

Update3: menu system works no ok. Stupid that I traced to much info :frowning: duh That’s why I thought that the changin event did not work…
Now next step for me is triggering dynamically new sound object to override the active mp3 object etc : Flashvar gets right xml to load, combobox items linked with directory placed mp3’s Now also try to embed id3 info or putting it als an extra xml thing much handier I guess!

import fl.controls.ComboBox;
import fl.data.DataProvider;
import flash.events.Event;
import flash.events.MouseEvent;

var dp:DataProvider = new DataProvider();
//dp.addItem({label:"item 1a"});
//dp.addItem({label:"item 2a"});

var myComboBox:ComboBox = new ComboBox()
combo.dataProvider = dp;
combo.move(100, 20);
addChild(combo);




var menuItem:MovieClip;// Libraryitem met linkage / class: MenuItem
var xml:XML;
var xmlArray:Array = new Array();
var xmlList:XMLList;
var xmlMenu:URLLoader = new URLLoader();
// inladen xml bestand
xmlMenu.load(new URLRequest("menu.xml"));
// als xml-bestand helemaal is geladen voer functie uit
xmlMenu.addEventListener(Event.COMPLETE, pushToArray);
// deze functie duwt waarden in een array en sorteert deze
function pushToArray(event:Event):void
{
        xml = XML(event.target.data);
        xmlList = xml.children();
        for (var i:Number = 0; i < xmlList.length(); i++)
        {
                xmlArray.push(xmlList*);
        }
        //xmlArray.sort();
        trace(xmlArray);
        buildMenu();
}
// de gesorteerde menuitems worden vervolgens gekoppeld aan een instance van de button genaamd MenuItem

function buildMenu()
{
        for (var i:uint = 0; i < xmlArray.length; i++)
        {
                //var menuItem:MenuItem = new MenuItem();
                //menuItem.x = 25;
                //menuItem.y = i * 40;
                //menuItem.displayText = xmlArray*; // setter
                //menuItem.tekst.text = menuItem.displayText; // getter
				dp.addItem({label:xmlArray*,data:xmlArray*});  // setter
                
                //addChild(menuItem);
                //combo.buttonMode = true;
				
                	combo.addEventListener(Event.CHANGE, test );
				
				
        }
}



function test(event:Event):void{
	combo.labelFunction = nameLabelFunction;
	trace("Selectedt:"+combo.selectedItem.label);
}

function nameLabelFunction(item:Object):String {
	//trace(item.label);
    return item.label;
}