Posted By

burnandbass on 09/18/12


Tagged


Versions (?)

after effects - data files to AS3 parser, frames number fixer


 / Published in: ActionScript 3
 

If you need to read data files from Adobe After Effects in Flash and want to parse them... AAE exports every scene from frame 0, no matter where on the movie the scene starts. This is a good and easy way to fix frame numbering and make it easier for Flash to parse/read them.

  1. package {
  2.  
  3. import flash.display.MovieClip;
  4. import flash.display.*;
  5. import flash.events.*;
  6. import flash.net.*;
  7. import flash.net.URLRequest;
  8.  
  9. public class Main extends MovieClip {
  10.  
  11. /*
  12. Author: Chrysto Panayotov ( burnandbass[at]gmail.com )
  13. Affter effects data files to AS3 conversion;
  14. */
  15.  
  16. private var finalData:String = "";
  17.  
  18. public function Main() {
  19. //add here path to the after effects data file
  20. var a:URLLoader = new URLLoader(new URLRequest("temp.txt"));
  21. a.addEventListener(Event.COMPLETE, onComplete);
  22. }
  23.  
  24. private function onComplete(event:Event):void{
  25. var tempArray:Array = String(event.target.data).split("\n");
  26.  
  27. //add here the frame the scene occure
  28. var startNum:Number = 11;
  29.  
  30. for(var i:uint = 0; i<tempArray.length; i++ ){
  31. var line:String = String(tempArray[i]).replace(/^\s+|\s+$/g, '');
  32. line.replace(" ", " ");
  33. var startRegExpress:RegExp = /^\D/g;
  34. var sectionRegExpress:RegExp = /^Effects/g
  35. if( ! startRegExpress.test( line )){
  36. var sections:Array = line.split("\t");
  37. if(sections[0] != undefined && sections[1] != undefined && sections[2] != undefined){
  38. var _frameNum:Number = Math.ceil(Number( sections[0] ));
  39. var _pointX:Number = sections[1];
  40. var _pointY:Number = sections[2];
  41. _frameNum = _frameNum + startNum;
  42. finalData += _frameNum + " : " + _pointX + " , " + _pointY + "\n";
  43. }
  44. } else if(sectionRegExpress.test( line ) ) {
  45. finalData += "\n\n" + line + "\n";
  46. }
  47.  
  48. }
  49. trace(finalData);
  50. }
  51.  
  52.  
  53.  
  54. }//end
  55. }

Report this snippet  

You need to login to post a comment.