Skip to content

Commit

Permalink
Improvements to embedded SWF content
Browse files Browse the repository at this point in the history
  • Loading branch information
jgranick committed Jul 24, 2013
1 parent d2a7d06 commit b8bf56c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 40 deletions.
30 changes: 19 additions & 11 deletions helpers/FlashHelper.hx
Original file line number Diff line number Diff line change
Expand Up @@ -243,25 +243,33 @@ class FlashHelper {

} else if (type == AssetType.IMAGE) {

var src = name;

if (ext == "jpg" || ext == "png" || ext == "gif") {
if (inAsset.data != null) {
outTags.push (TBitsJPEG (cid, JDJPEG2 (inAsset.data)));

if (!FileSystem.exists (src)) {
} else {

var src = name;

if (ext == "jpg" || ext == "png" || ext == "gif") {

Sys.println ("Warning: Could not find image path \"" + src + "\"");
if (!FileSystem.exists (src)) {

Sys.println ("Warning: Could not find image path \"" + src + "\"");

} else {

var bytes = File.getBytes (src);
outTags.push (TBitsJPEG (cid, JDJPEG2 (bytes)));

}

} else {

var bytes = File.getBytes (src);
outTags.push (TBitsJPEG (cid, JDJPEG2 (bytes)));
throw ("Unknown image type:" + src );

}

} else {

throw ("Unknown image type:" + src );

}

} else if (type == AssetType.FONT) {
Expand Down
53 changes: 25 additions & 28 deletions helpers/SWFHelper.hx
Original file line number Diff line number Diff line change
Expand Up @@ -125,46 +125,43 @@ class SWFHelper {

for (library in project.libraries) {

#if swf

if (library.type == LibraryType.SWF) {

project.haxelibs.push (new Haxelib ("swf"));
project.assets.push (new Asset (library.sourcePath, "libraries/" + library.name + ".swf", AssetType.BINARY));

#if swf
if (project.target == Platform.HTML5) {

var bytes = ByteArray.readFile (library.sourcePath);
var swf = new SWF (bytes);
var exporter = new SWFLiteExporter (swf.data);
var swfLite = exporter.swfLite;
} else if (library.type == LibraryType.SWF_LITE) {

project.haxelibs.push (new Haxelib ("swf"));

var bytes = ByteArray.readFile (library.sourcePath);
var swf = new SWF (bytes);
var exporter = new SWFLiteExporter (swf.data);
var swfLite = exporter.swfLite;

for (id in exporter.bitmaps.keys ()) {

for (id in exporter.bitmaps.keys ()) {

var bitmapData = exporter.bitmaps.get (id);
var symbol:BitmapSymbol = cast swfLite.symbols.get (id);
symbol.path = "libraries/bin/" + id + ".png";
swfLite.symbols.set (id, symbol);

var asset = new Asset ("", symbol.path, AssetType.IMAGE);
asset.data = bitmapData.encode ("png");
project.assets.push (asset);

}
var bitmapData = exporter.bitmaps.get (id);
var symbol:BitmapSymbol = cast swfLite.symbols.get (id);
symbol.path = "libraries/bin/" + id + ".png";
swfLite.symbols.set (id, symbol);

var asset = new Asset ("", "libraries/" + library.name + ".dat", AssetType.TEXT);
asset.data = Serializer.run (swfLite);
var asset = new Asset ("", symbol.path, AssetType.IMAGE);
asset.data = bitmapData.encode ("png");
project.assets.push (asset);

} else {
#end

project.assets.push (new Asset (library.sourcePath, "libraries/" + library.name + ".swf", AssetType.BINARY));

#if swf
}
#end

var asset = new Asset ("", "libraries/" + library.name + ".dat", AssetType.TEXT);
asset.data = Serializer.run (swfLite);
project.assets.push (asset);

}

#end

}

}
Expand Down
1 change: 1 addition & 0 deletions project/LibraryType.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package project;
enum LibraryType {

SWF;
SWF_LITE;
XFL;

}
15 changes: 14 additions & 1 deletion project/NMMLParser.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ class NMMLParser extends NMEProject {

var path = PathHelper.combine (extensionPath, substitute (element.att.path));
var name = "";
var type = null;

if (element.has.name) {

Expand All @@ -1055,7 +1056,19 @@ class NMMLParser extends NMEProject {

}

libraries.push (new Library (path, name));
if (element.has.type) {

switch (element.att.type) {

case "swf": type = LibraryType.SWF;
case "swflite": type = LibraryType.SWF_LITE;
case "xfl": type = LibraryType.XFL;

}

}

libraries.push (new Library (path, name, type));

case "ssl":

Expand Down

0 comments on commit b8bf56c

Please sign in to comment.