Nicolas Cannasse 17 years ago
parent
commit
fd84acc90d
3 changed files with 26 additions and 15 deletions
  1. 11 4
      genswf.ml
  2. 13 9
      main.ml
  3. 2 2
      std/flash9/Boot.hx

+ 11 - 4
genswf.ml

@@ -22,6 +22,12 @@ open As3hl
 open Genswf9
 open Type
 
+type swfinfos = {
+	mutable swf_version : int;
+	mutable swf_header : (int * int * float * int) option;
+	mutable swf_lib : string option;
+}
+
 type context = {
 	mutable f8clips : string list;
 	mutable f9clips : f9class list;
@@ -139,7 +145,8 @@ let add_as3_code ctx data types =
 let add_as3_clips ctx cl =
 	ctx.f9clips <- List.filter (fun c -> c.f9_cid <> None) cl @ ctx.f9clips
 
-let generate file ver header infile types hres =
+let generate file infos types hres =
+	let ver = infos.swf_version in
 	let t = Plugin.timer "generate swf" in
 	let file , codeclip = (try let f , c = ExtString.String.split file "@" in f, Some c with _ -> file , None) in
 	let ctx = {
@@ -213,9 +220,9 @@ let generate file ver header infile types hres =
 		let clips9 = (if ver = 9 then [tag (TF9Classes ctx.f9clips)] else []) in
 		sandbox @ debug @ content @ clips @ code @ as3code @ clips9
 	in
-	let swf = (match infile with
+	let swf = (match infos.swf_lib with
 		| None ->
-			let header , bg = (match header with None -> default_header ver | Some h -> convert_header ver h) in
+			let header , bg = (match infos.swf_header with None -> default_header ver | Some h -> convert_header ver h) in
 			let tagbg = tag (TSetBgColor { cr = bg lsr 16; cg = (bg lsr 8) land 0xFF; cb = bg land 0xFF }) in
 			let tagshow = tag TShowFrame in
 			(header,build_swf [tagbg] @ [tagshow])
@@ -223,7 +230,7 @@ let generate file ver header infile types hres =
 			let file = (try Plugin.find_file file with Not_found -> failwith ("File not found : " ^ file)) in
 			let ch = IO.input_channel (open_in_bin file) in
 			let h, swf = (try Swf.parse ch with _ -> failwith ("The input swf " ^ file ^ " is corrupted")) in
-			let header , tagbg = (match header with
+			let header , tagbg = (match infos.swf_header with
 				| None ->
 					{ h with h_version = ver }, None
 				| Some h ->

+ 13 - 9
main.ml

@@ -17,6 +17,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *)
 open Printf
+open Genswf
 
 type target =
 	| No
@@ -188,11 +189,13 @@ try
 	let usage = "Haxe Compiler " ^ version_str ^ " - (c)2005-2008 Motion-Twin\n Usage : haxe.exe [options] <class names...>\n Options :" in
 	let classes = ref [([],"Std")] in
 	let target = ref No in
-	let swf_in = ref None in
 	let xml_out = ref None in
 	let main_class = ref None in
-	let swf_version = ref 8 in
-	let swf_header = ref None in
+	let swf_infos = {
+		swf_version = 8;
+		swf_header = None;
+		swf_lib = None;
+	} in
 	let hres = Hashtbl.create 0 in
 	let cmds = ref [] in
 	let excludes = ref [] in
@@ -239,7 +242,7 @@ try
 		),"<file> : compile code to JavaScript file");
 		("-as3",Arg.String (fun dir ->
 			check_targets();
-			swf_version := 9;
+			swf_infos.swf_version <- 9;
 			Plugin.define "as3gen";
 			Typer.forbidden_packages := ["js"; "neko"];
 			target := As3 dir;
@@ -250,11 +253,11 @@ try
 			target := Swf file
 		),"<file> : compile code to Flash SWF file");
 		("-swf-version",Arg.Int (fun v ->
-			swf_version := v;
+			swf_infos.swf_version <- v;
 		),"<version> : change the SWF version (6,7,8,9)");
 		("-swf-header",Arg.String (fun h ->
 			try
-				swf_header := Some (match ExtString.String.nsplit h ":" with
+				swf_infos.swf_header <- Some (match ExtString.String.nsplit h ":" with
 				| [width; height; fps] ->
 					(int_of_string width,int_of_string height,float_of_string fps,0xFFFFFF)
 				| [width; height; fps; color] ->
@@ -264,7 +267,8 @@ try
 				_ -> raise (Arg.Bad "Invalid SWF header format")
 		),"<header> : define SWF header (width:height:fps:color)");
 		("-swf-lib",Arg.String (fun file ->
-			swf_in := Some file
+			if swf_infos.swf_lib <> None then raise (Arg.Bad "Only one SWF Library is allowed");
+			swf_infos.swf_lib <- Some file
 		),"<file> : add the SWF library to the compiled SWF");
 		("-neko",Arg.String (fun file ->
 			check_targets();
@@ -402,7 +406,7 @@ try
 		   to accidentaly delete a source file. *)
 		if not !no_output && file_extension file = "swf" then delete_file file;
 		Plugin.define "flash";
-		Plugin.define ("flash"  ^ string_of_int !swf_version);
+		Plugin.define ("flash"  ^ string_of_int swf_infos.swf_version);
 	| Neko file ->
 		if not !no_output && file_extension file = "n" then delete_file file;
 		Plugin.define "neko";
@@ -432,7 +436,7 @@ try
 		| Swf file ->
 			do_auto_xml file;
 			if !Plugin.verbose then print_endline ("Generating swf : " ^ file);
-			Genswf.generate file (!swf_version) (!swf_header) (!swf_in) types hres
+			Genswf.generate file swf_infos types hres
 		| Neko file ->
 			do_auto_xml file;
 			if !Plugin.verbose then print_endline ("Generating neko : " ^ file);

+ 2 - 2
std/flash9/Boot.hx

@@ -111,7 +111,7 @@ class Boot extends flash.display.MovieClip {
 			format.font = "_sans";
 			tf.defaultTextFormat = format;
 			tf.selectable = false;
-			tf.width = mc.stage.stageWidth;
+			tf.width = if( mc.stage == null ) 800 else mc.stage.stageWidth;
 			tf.autoSize = flash.text.TextFieldAutoSize.LEFT;
 			tf.mouseEnabled = false;
 		}
@@ -126,7 +126,7 @@ class Boot extends flash.display.MovieClip {
 		tf.text = lines.join("\n");
 		var stage = flash.Lib.current.stage;
 		if( stage == null )
-			throw "Loaded movie not ready to trace, wait a few frames";
+			return;
 		while( tf.height > stage.stageHeight ) {
 			lines.shift();
 			tf.text = lines.join("\n");