I am going to post the class files for the MXNA WebService App I put together over the weekend. I will post them as I add the comments.

I will eventually post all of the source, but I want to work out all of the kinks first.

The first class I am posting, MXNAAppController is the controller for the application. It handles all communication with the web services on the server, and contains a single view class, that contains most of the UI elements for the app.

So, if you find any bugs, or have any suggestions, post them in the comments.

[code]import mx.containers.Window;import com.macromedia.mxna.MXNAWebService;import;import mx.controls.Alert;import mx.controls.ProgressBar;/* Associated with the main app controller clip */class extends MovieClip{/*Window Component for Background*/private var bgWindow:Window;/*MXNA WebService Class to Load Data*/private var ws:MXNAWebService;/*Main App View*/private var feedView:MXNAFeedView;/*clip to block window component interaction*/private var blocker:MovieClip;/*Progress Bar Component*/private var pBar:ProgressBar;/*Used to cache category data*/private var feedCache:Object;private var so:SharedObject;/*Constructor. We do everything in onLoad to be sureeverything has initialized*/public function MXNAAppController(){}/*Called by Flash when the clip is laoded on stage. We do a bunch ofinitialization here.*/private function onLoad():Void{feedCache = new Object();//set the clip to catch mouse events to the Window Component title bar.//we jsut want to use it for the backgroundblocker._alpha = 0;blocker.onRelease = function(){};blocker.useHandCursor = false;bgWindow.title = “MXNA WebService Example”;//braodcast when the user selects a categoryfeedView.addEventListener(“onSelectCategory”, this);//Custom class that provides an interface / API to the MXNA webservicesws = new MXNAWebService();//event when categories load from serverws.addEventListener(“onGetCategories”, this);//event when posts load from serverws.addEventListener(“onGetPostsByCategory”, this);//event when an error occursws.addEventListener(“onFault”, this);//see if categories have been laoded before. If so, use = SharedObject.getLocal(“MXNAWebServiceExample”);var categories =;if(categories != undefined){setCategories(categories);}else{enableProgress(true, “Loading Categories…”);//if categories not saved from before, then load them from the;}}public function onActivate(Void):Void{}//utility methods that takes an array of categories and sets them in the UI//passing them to the feedViewprivate function setCategories(categories:Array):Void{feedView.setCategories(categories, “CATEGORY”);//when the categories are loaded, lets go get the first batch of posts//so the user has something to look at.getPostsByCategory(“All”);}//takes a category, and gets the posts for that category from the serverprivate function getPostsByCategory(category:String):Void{enableProgress(true, “Loading ” + category + ” Feeds…”);ws.getPostsByCategory(category);}//method to manage the progress bar.//We are usign it in indetermindate mode, so, we need to turn it off when//it is not being used (i.e. make it invisible).private function enableProgress(enabled:Boolean, label:String):Void{if(label == undefined){label = “”;}pBar.indeterminate = enabled;pBar.label = label;pBar.enabled = enabled;pBar._visible = enabled;//if something is being loaded, we need to disable the UI in order to//keep things in syncfeedView.enabled = !enabled;}//event listener method, called when categories are loaded from the server.private function onGetCategories(eventObj:Object):Void{enableProgress(false);//contains an array of string category namesvar results:Array = eventObj.categories;//we need to add the “All” option since this is not returned from//the serverresults.unshift({CATEGORY:”All”});//lets save the categories in an SO, so we don’t have to load them next// = results;so.flush();setCategories(results);}//event listener method, called when the user selects a category from the UI.private function onSelectCategory(eventObj:Object):Void{//category namevar category:String = eventObj.category;//lets see if the feeds are in the cacheif(feedCache[category] != undefined){//if so, use itfeedView.dataProvider = feedCache[category];return;}//otherwise, go to the server to get the feeds for the categorygetPostsByCategory(category);}//event listener method, called when posts are loade from the serverprivate function onGetPostsByCategory(eventObj:Object):Void{enableProgress(false);//add them to the cache.feedCache[eventObj.category] = eventObj.feeds;//send them to the feedView to be displayedfeedView.dataProvider = eventObj.feeds;}//called if an error occurs. only broadcast by MXNA class right now.private function onFault(faultObj:Object):Void{var info:Object = faultObj.fault;//show an Alert box with some,info.faultstring,Alert.OK,this,null,”errorIcon”,Alert.OK);feedView.enabled = false;enableProgress(false);}}[code]

Btw, big ups to Sean Voisen for the AS 2 support in his MovableType CodeBeautifier.

8 Responses to

  1. Marcos Neves says:

    seen’s fine, but where can I find the importscom.macromedia.mxna ?

  2. Dominick says:

    nice code, still have to look it over. I’m actually just gazing at the codebeautifier.. wow.. nice job sean.

  3. mike chambers says:

    >com.macromedia.mxnaI havent posted these yet, as they are still be tweaked and commented.I will post the rest of the classes soon.mike

  4. Dirk Eismann says:

    Inspired by your great app I tried to built a custom WebService class by my own but I were not able to extend the built-in WebService class:// this failsclass WebServiceEx extends WebService {}// this fails, tooimport*;class WebServiceEx extends WebService {}The compiler keeps complaining that it can’t find the WebService class. I triple checked the classpath but it just won’t work.Any ideas?

  5. mike chambers says:

    you have to manually include the classes by following these steps:1. Window > Other Panels > Common Libraries > Classes2. Drag the WebServicesClasses Symbol from the library onto the stage.3. Delete the WebServicesClasses Symbol (steps 2 and 3 puts it in your library).mike

  6. Brandon says:

    Great Web News App.I would like to build my own web service,and class Files.How can I start learning how to do that?Any Info Would Help.

  7. Jordan says:

    What about when you’re writing a class file and you can’t drag something onto the stage? How do you access the webservice classes?

  8. David Lee says:

    “What about when you’re writing a class file and you can’t drag something onto the stage? How do you access the webservice classes?”Yes how do you do this?