View Full Version : Delegate events for ComboBox
casey
11-20-2005, 03:00 PM
This is my first post here and I'm just hoping someone advanced enough will be able to lend a hand here.
What I have in the link below is a combobox loaded by an xml document that performs 2 events:
-loads an FLV into the player
-changes text in a textfield
The purpose os to provide accessiblity for the deaf displaying the movie info/captions.
I'm able to make the combobox do one or the other but not both. I've used the import mx.utils.Delegate function to try to use dupicate change handlers but with no luck..
I've posted my example and zipped sources here. (http://www.fairhopenewmedia.com/movies/index.html)
ANY help is greatly appreciated.
Hi,
I didn't look at the zip file or demo link. I only have FlashMX and assume your using a newer version. What your describing would not be difficult to achieve. The way I would set it up is to use the label property to load the flv and use the data property to load the textfile or text to be put into a textfield. Say you have a change handler named, "myChanger", the AS would look something like........
function myChanger(){
myLabel=myCbox.getSelectedItem().label;
myData=myCbox.getSelectedItem().data;
trace(myLabel);
trace(myData);
}
The above is a basic structure for a change handler. You could extend that function or allow a button to load the content. That depends on how your project is set up.
hope it helps
NTD
casey
11-21-2005, 07:12 PM
Tat helps a little I suppose.
I wish I could have done it that simple to start but I may have complicated it.
I have three items on stage:
combobox: "cbMovie"
text field: "ta"
video box: "MyVideo"
(and ofcourse pausebutton and playbutton)
Can you look at my AS below and tell me what you might do?
I appreciate your reply.
// import this so it can be used to set the scope of the combobox listener
import mx.utils.Delegate;
// declare variables
var people:Array = [{pname:"Choose one"}];
var update:String;
var dirpath:String;
//GlobalSettings @ start
playButton._visible = false;
//Netconnection
var nc:NetConnection = new NetConnection ();
nc.connect (null);
var ns:NetStream = new NetStream (nc);
ns.setBufferTime (3);
myVideo.attachVideo (ns);
//PlayControl
playButton.onRelease = function() {
ns.pause()
playButton._visible = false;
pauseButton._visible = true;
}
pauseButton.onRelease = function() {
ns.pause();
playButton._visible = true;
pauseButton._visible = false;
}
stopButton.onRelease = function() {
ns.pause();
playButton._visible = true;
pauseButton._visible = false;
}
//LoadBar at progressive Download
var videoInterval = setInterval(videoStatus, 100);
var amountLoaded:Number;
var duration:Number;
ns["onMetaData"] = function(obj) {
duration = obj.duration;
}
function videoStatus() {
amountLoaded = ns.bytesLoaded / ns.bytesTotal;
loader.loadbar._width = amountLoaded * 319;
loader.playHead._x = ns.time / duration * 319;
}
//Textfield
this.createTextField("time_txt",this.getNextHighestDepth(),294,255,100,22);
time_txt.multiline = false;
time_txt.selectable = false;
time_txt.align = "right";
var time_interval:Number = setInterval (checkTime, 500, ns);
function checkTime (ns:NetStream)
{
var ns_seconds:Number = ns.time;
var minutes:Number = Math.floor (ns_seconds / 60);
var hours:Number = Math.floor (minutes / 60);
var seconds = Math.floor (ns_seconds % 60);
if (seconds < 10)
{
seconds = "0" + seconds;
}
time_txt.text = hours + ":" + minutes + ":" + seconds;
}
// create a new color object associated with the bgcolor movieclip
var bgcol:Color = new Color(bgcolor);
// initialize items on stage
_global.style.setStyle("fontFamily","Verdana");
_global.style.setStyle("fontSize",11);
_global.style.setStyle("color", 0x000000);
// set up the XML instance
var peoplexml:XML = new XML();
peoplexml.ignoreWhite = true;
// define what should happen when the XML loads
// (read data into update, dirpath, and people variables)
peoplexml.onLoad = function(success:Boolean) {
if (success) {
// make a handle to the root node in the xml
var mainnode:XMLNode = this.firstChild;
update = mainnode.attributes.lastupdate;
dirpath = mainnode.attributes.dir;
// set up an array of all person nodes
var peoplenodes:Array = this.firstChild.childNodes;
for (var i:Number = 0; i < peoplenodes.length; i++) {
// for each person node:
var personnode:XMLNode = peoplenodes[i];
people.push({i:i+1, pname:personnode.attributes.name, bgcolor:parseInt(personnode.attributes.bgcolor, 16), movieurl:personnode.childNodes[0].attributes.url, desc:personnode.childNodes[1].firstChild.nodeValue , links:personnode.childNodes[2].firstChild.nodeValu e});
}
// data is all read and put in the right place -- now setup the screen
// using this data
setup();
} else {
trace('error reading XML');
}
}
function setup() {
// set up cbMovie dropdown
cbMovie.labelField = "pname";
cbMovie.dataProvider = people;
//I DONT KNOW WHAT IM DOING HERE
cbMovie.addEventListener("change",Delegate.create(this, loadScreen, loadFLV));
}
function loadScreen(evt:Object) {
var thisitem:Object = evt.target.selectedItem;
ta.text = thisitem.desc;
ta.vPosition = 0;
}
//I DONT KNOW WHAT IM DOING HERE
function loadFLV(evt:Object) {
var movList:Object = new Object ();
movList.change = function () {
ns.play(cbMovie.getItemAt(cbMovie.selectedIndex).l abel);
pauseButton._visible = false;
playButton._visible = true;
}
};
// start the xml loading
peoplexml.load("people.xml");
Hi,
Yes, your code is rather complex. As long as you know what info is coming into the combobox and can set it up, you can check the label selected in the change handler function. It appears your only using the label property of the combobox. You can also use a data property for each label field. In the same manner you populate the combobox with labels, populate the data property in the same manner. I would suggest creating a test movie with only the combobox to better understand how it works. I have several cbox demo's but they are all in MX format. Components changed slightly with the release of FlashMX2004.
Powered by vBulletin™ Version 4.1.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.