Well you have two issues. First your building a variable that only exists within the .change function. Due to scope issues your going to have a hard time accessing it outside the function.
To solve this you need to create a variable outside the function and then set its value when the on change fires. So:
// create holder varialbes
var selItem = "";
var selLabel = "";
myComboBoxListener = new Object();
myComboBoxListener.change = function(eventObj) {
var eventSource = eventObj.target;
var theSelectedItem = eventSource.selectedItem;
var theSelectedItemLabel = theSelectedItem.data;
// attach your vars to the holder vars
selItem = theSelectedItem;
selLabel = theSelectedLabel;
// trace the variables here to show that they've changed
trace("item = "+selItem+" and label= "+selLabel);
};
myComboBox.addEventListener("change", myComboBoxListener);
// If you trace the vars here they'll be blank because the event hasn't fired yet.
trace("item = "+selItem+" and label= "+selLabel);
- // create holder varialbes
- var selItem = "";
- var selLabel = "";
-
- myComboBoxListener = new Object();
- myComboBoxListener.change = function(eventObj) {
- var eventSource = eventObj.target;
- var theSelectedItem = eventSource.selectedItem;
- var theSelectedItemLabel = theSelectedItem.data;
- // attach your vars to the holder vars
- selItem = theSelectedItem;
- selLabel = theSelectedLabel;
-
- // trace the variables here to show that they've changed
- trace("item = "+selItem+" and label= "+selLabel);
- };
- myComboBox.addEventListener("change", myComboBoxListener);
-
- // If you trace the vars here they'll be blank because the event hasn't fired yet.
- trace("item = "+selItem+" and label= "+selLabel);
-
-
Now depending on what you need to do with the variables in php you could make the call right inside the on change function but its probably easier to have a separate function to handle all that which you call inside the listener.
// create holder varialbes
var selItem = "";
var selLabel = "";
myComboBoxListener = new Object();
myComboBoxListener.change = function(eventObj) {
var eventSource = eventObj.target;
var theSelectedItem = eventSource.selectedItem;
var theSelectedItemLabel = theSelectedItem.data;
// attach your vars to the holder vars
selItem = theSelectedItem;
selLabel = theSelectedLabel;
// function to run
cbchanged();
};
myComboBox.addEventListener("change", myComboBoxListener);
// function to run on change
function cbchanged(){
trace("cb changed. new item = "+selItem+" and new label= "+selLabel);
}
- // create holder varialbes
- var selItem = "";
- var selLabel = "";
-
- myComboBoxListener = new Object();
- myComboBoxListener.change = function(eventObj) {
- var eventSource = eventObj.target;
- var theSelectedItem = eventSource.selectedItem;
- var theSelectedItemLabel = theSelectedItem.data;
- // attach your vars to the holder vars
- selItem = theSelectedItem;
- selLabel = theSelectedLabel;
-
- // function to run
- cbchanged();
-
- };
- myComboBox.addEventListener("change", myComboBoxListener);
-
- // function to run on change
- function cbchanged(){
- trace("cb changed. new item = "+selItem+" and new label= "+selLabel);
- }
-
Obviously there are a lot of ways to simplify that code but its good to know whats going on.
Second there are a couple ways to pass that data out to php/javascript etc. Take a look at both
sendAndLoadVars and
externalInterface to find the best one for your setup.
If at first you don't succeed F1... If that doesn't work try Google!
//// Designer, Developer & Teacher - Interactive, Motion and 3D \\\\
Portfolio at WhenImNotSleeping.com