all groups > flash actionscript > january 2005 >
You're in the

flash actionscript

group:

Can't update _global variables


Can't update _global variables joe28sfl
1/23/2005 6:58:00 PM
flash actionscript:
I am writing a real estate app using Flash 2004 Pro and screens (form based).
On the top level screen I have defined a global variable that sets a default
property id number called '_global.selectedListing'. On a chlid screen, I have
listings shown using a databgrid so that the user can select a property and get
more information on it. I have an on(change) event listener that tries to
update the global property id variable when the user clicks on a row in the
datagrid. For some reason, it will not update the variable. I have tried it
with both '_global.selectedListing=event.target.selectedIndex;' and
'selectedListing=event.target.selectedIndex;' Can anyone tell me why this is
not working? I have posted a draft of the swf up to
http://www.realtycds.com/demo/mainInterface.swf Thanks, Joe
Re: Can't update _global variables barn
1/23/2005 10:19:07 PM
No one will be able to discern any possible problems by viewing your SWF file.
Copy and past your code into an 'Attach Code' window (don't retype, as that,
more often than not, either introduces errors that do not exist in the actual
code, and/or omits errors that DO exist in the actual code).
Re: Can't update _global variables Jeckyl
1/24/2005 10:03:59 AM
_global.selectedListing=event.target.selectedIndex

that is what it should be.. if its not working, then you've got some OTHER
problem in stuff you're not showing us. This is very frequently the case
with a novice (or even some pro's) .. they show a line of code where the
symptom of the problem shows (or where they THINK the problem is) when its
really some other problem somewhere else (sometime might even be the line of
code just before etc).
--
All the best,
Jeckyl

Re: Can't update _global variables joe28sfl
1/24/2005 7:02:54 PM
Barn, I have attached the code that I am havinf trouble with. I get the
following error on the tour page when previewing it: Error opening URL
'file:///C|/CFusionMX/wwwroot/realtycds/demo/listings/undefined/undefined.xml'
So it seems to me that it can't find a value for '_global.selectedListing'. I
also tried it without the '_global.' but got the same error. Any ideas?

//This actionscript it attached to the slide that holds the datagrid
on (reveal) {

//Load the xml file into a variable for later use
var listingsXML:XML=new XML();
listingsXML.ignoreWhite=true;
listingsXML.load("Output.xml");

// Trigger Data Source Behavior
// Macromedia 2003
myReceiveXMLConnector.trigger();
listingsDataGrid.rowHeight=70;
listingsDataGrid.borderStyle=none;
listingsDataGrid.getColumnAt(0).width=95; //Picture Field
listingsDataGrid.getColumnAt(0).sortable = false;
listingsDataGrid.getColumnAt(0).headerText ="Photo";
listingsDataGrid.getColumnAt(1).width=150; //Address Field
listingsDataGrid.getColumnAt(1).sortable = false;
listingsDataGrid.getColumnAt(1).headerText ="Address";
listingsDataGrid.getColumnAt(2).width=50; //Bedrooms Field
listingsDataGrid.getColumnAt(2).headerText ="Beds";
listingsDataGrid.getColumnAt(3).width=50; //Bathrooms Field
listingsDataGrid.getColumnAt(3).headerText ="Baths";
listingsDataGrid.getColumnAt(4).width=70; //Price Field
listingsDataGrid.getColumnAt(4).headerText ="Listed At";
listingsDataGrid.getColumnAt(5).width=70; //SQFT Field
listingsDataGrid.getColumnAt(5).headerText ="SqFt";
listingsDataGrid.getColumnAt(0).cellRenderer="ImageRenderer";

/*
for (var i=0;i<listingsDataGrid.length;i++)
{

trace(listingsXML.firstChild.childNodes[event.target.selectedIndex].attributes
..picture);
}
*/
var myListener = new Object();
myListener.change = function(event) {
_parent.titles.gotoAndStop(3);
_parent.listingGrid.visible=false;
_parent.slideShow.visible=true;
trace("selected index is: " +event.target.selectedIndex);
_global.selectedListing=event.target.selectedIndex;
trace("_global.selectedListing value= " +selectedListing);
};
listingsDataGrid.addEventListener("change", myListener);
listingsDataGrid.setStyle("alternatingRowColors", [0xFFFFFF,0xFFFFFF]);
}


//This actionscript is attached to a sibling screen that shows virtual tours
after the user selects a property from the datagrid screen
on (load){
tours_xml = new XML();
tours_xml.onLoad = startSlideShow;

tours_xml.load("listings/"+_global.selectedListing+"/"+_global.selectedListing+
".xml");
tours_xml.ignoreWhite = true;

...other non related code....
}
Re: Can't update _global variables joe28sfl
1/24/2005 7:15:16 PM
An update to my last post.... I just added the following to the tours screen
to create a default value for the global variable if it was not defined: if
(_global.selectedListing == undefined) _global.selectedListing = 664; Testing
it now return the tours for listingID 664. So the variable is definately not
being created on the datagrid screen. Any idea why not?
Re: Can't update _global variables joe28sfl
1/24/2005 9:24:02 PM
Jecky, I found the problem and fixed it. I had actionscript in another part
of the file that I forgot to delete and it was messing it up. My trace
statements are not spitting out the index correctly (0,1,2,3 etc). What I am
trying to do though is to get the value of a specific item at that index. The
first column stores a propertyID # so I need to figure out the code equivalent
to 'Get the propertyID value at event.target.selectedIndex'. Any ideas?
Thanks, Joe
Re: Can't update _global variables joe28sfl
1/24/2005 9:25:27 PM
Correction to my last post:

My trace statements are NOW spitting out the index correctly (0,1,2,3 etc).
Re: Can't update _global variables Jeckyl
1/25/2005 7:27:31 AM
so ... what do the two trace statements in your change function give you?
--
All the best,
Jeckyl

AddThis Social Bookmark Button