if (xfa.host.name == "Flash") { // ActionScript in Guide (Flex) space // The XML object is a "Top Level" object in Flex which means we don't need to import its class. var url = "http://forms.stefcameron.com/services/movies/"; // add any actor or category filters if (ActorList.rawValue != null || CategoryList.rawValue != null) { url += "?"; if (ActorList.rawValue != null) url += "actor=" + ActorList.rawValue; // this will be the actor ID if (CategoryList.rawValue != null) { if (ActorList.rawValue != null) url += "&"; url += "category=" + CategoryList.rawValue; // this will be the category ID } } // disable the GetMovies button while we wait for the data this.access = "readOnly"; // send the request to the Movie Service FlexHttpService.send ( // URL to query url, // result handler function(movieListXml:XML):void { trace("=== SUCCESS retrieving movie data:\n" + movieListXml.toXMLString()); // get the Listing table var listingTable = xfa.form.movieList.Listing; if (listingTable._MovieRow.count > 0) listingTable._MovieRow.setInstances(0); // remove any initial place-holder instances // add a new row for each movie in the catalog returned for each (var movieXml in movieListXml.elements()) { var newMovieRow = listingTable._MovieRow.addInstance(0); newMovieRow.Title.rawValue = movieXml.title; newMovieRow.Actor.rawValue = movieXml.actorName; newMovieRow.Category.rawValue = movieXml.catName; newMovieRow.Cost.rawValue = movieXml.cost; } // re-enable the GetMovies button var getMoviesBtn = xfa.form.movieList.GuideObjects.GetMovies; getMoviesBtn.access = "open"; // set the match count var matchCount = xfa.form.movieList.GuideObjects.MatchCount; matchCount.rawValue = listingTable._MovieRow.count; }, // fault handler function(fault:String):void { import mx.controls.Alert; trace("=== ERROR retrieving movie data: " + fault); Alert.show("Error retrieving movie data: " + fault); // re-enable the GetMovies button var getMoviesBtn = xfa.form.movieList.GuideObjects.GetMovies; getMoviesBtn.access = "open"; } ); }