AS3: My favorite helper functions


/ Published in: ActionScript 3
Save to your folder(s)

These are my favorite helper functions. getFlashVars() is used to quickly pull out variables from SWFObject2, getDevelopmentMode() is used to determine whether you are working locally on your machine or if the SWF is hosted on a server, getContextPath() is used to determine what directory the SWF is located


Copy this code and paste it in your HTML
  1. public function SlideShow( ){
  2. //If you are working locally on your computer, you will load manually load the xml file. Otherwise you will be receiving the xml file from SWFObject2
  3. xmlURL = ( getDevelopmentMode() === "Production" ) ? getFlashVars().xml : "./xml/data.xml";
  4.  
  5. //Capture where the SWF is living on the live site
  6. var currentLocationOfSWF:String = getContextPath();
  7. }
  8.  
  9. private function getFlashVars():Object
  10. {
  11. return Object( LoaderInfo( this.loaderInfo ).parameters );
  12. }
  13.  
  14. private function getDevelopmentMode():String
  15. {
  16. var dev:Boolean = new RegExp("file://").test( this.loaderInfo.loaderURL);
  17.  
  18. if( dev ) return "Development";
  19. else return "Production";
  20. }
  21.  
  22. private function getContextPath():String
  23. {
  24. var uri:String = getLoaderURL();
  25. return uri.substring(0, uri.lastIndexOf("/")) + "/";
  26. }
  27.  
  28. private function getLoaderURL():String
  29. {
  30. return this.loaderInfo.loaderURL;
  31. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.