PDA

View Full Version : finding a specific result[] on click



level4designs
June 7th, 2008, 01:16 PM
I am trying to handle my results from a amfphp remoting call... this is probably really easy problem, but one of my last problems to work on.

when I click on a product or image, I want to take all the details of that result[] and display elsewhere or set as a current product... this is kind of what I have...



public function handlesearchresults(results) {
var rslength = results.length;
for (var x= 0;x<rslength; x++) {
//create productholder for each product
var productholder:productholder_mc = new productholder_mc();
//set thumbnail position for this product
productholder.y = 20+(270*int(x/2));
productholder.x = (270*(x%2))+50;
productholder.productinformation_mc.prodtitle_txt. text = results[x].Title;
productholder.productinformation_mc.proddesc_txt.t ext = results[x].Description;
productholder.productinformation_mc.prodprice_txt. text = "$ "+results[x].Price;
productholder.addEventListener(MouseEvent.CLICK, buttonclickfunction);
function buttonclickfunction(event:MouseEvent):void {

//this is where I'm not sure what to put to track for each click

}
}




I have tried things like this, thinking I could point the information I click on to the correct stage location... but I think the [x] is always changing:


stage.getChildAt(0).productdetailsmain_mc.productd etails_mc.producttitle_txt.text = event.target.results[x].Title;


is there something easy to go in there that I'm missing that will allow this. equivilant in AS2.0 was as easy as productholder.thisone = x; then I could use the recordSet class to pull it with getItemAt(this.x) on an onRelease;... I know, I know, it's not there now...

thanks

level4designs
June 8th, 2008, 11:33 AM
ok, I did get a little further on this... stupid me. 1st thing I noticed was I needed result to be seen in the buttonclickfunction, so I made a var outside and assigned it the results...


private var searchresults:Array = new Array(); //located in my class, not in my function

so now in my buttonclickfunction I can do this...


searchresults[1].Title;

so my last problem now is to be able to track which loop variable "x" I am on and pass it along?

I need to be able to do this...


searchresults[x].Title; //or something similar to it?

level4designs
June 8th, 2008, 01:40 PM
fixed my own problem... found out that the movieclip class is dynamic... therefor you can create variables off of a movie clip just like the old days :)


productholder.num = x;
//this does work if productholder was a movie clip... cool

and then in my buttonclickfunction I can simply use...


searchresults[event.currentTarget.num].Title;