Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openfl dev compatibility fixes #15

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/swf/SWF.hx
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ class SWF extends EventDispatcher
symbol = data.getCharacter(charId);
}

// if (#if (haxe_ver >= 4.2) Std.isOfType #else Std.is #end (symbol, TagDefineButton2)) {

// return new SimpleButton (data, cast symbol);

// }
if (#if (haxe_ver >= 4.2) Std.isOfType #else Std.is #end (symbol, TagDefineButton2))
{
return new swf.runtime.SimpleButton(data, cast symbol);
}

return null;
}
Expand Down Expand Up @@ -143,11 +142,10 @@ class SWF extends EventDispatcher
}
}

// if (#if (haxe_ver >= 4.2) Std.isOfType #else Std.is #end (symbol, SWFTimelineContainer)) {

// return new MovieClip (cast symbol);

// }
if (#if (haxe_ver >= 4.2) Std.isOfType #else Std.is #end (symbol, SWFTimelineContainer))
{
return new swf.runtime.MovieClip(cast symbol);
}

return null;
}
Expand Down
14 changes: 7 additions & 7 deletions src/swf/exporters/SWFLiteExporter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ class SWFLiteExporter
if (object.placeMatrix != null)
{
var matrix = object.placeMatrix.matrix;
matrix.tx *= (1 / 20);
matrix.ty *= (1 / 20);
matrix.tx = object.placeMatrix.translateX / 20;
matrix.ty = object.placeMatrix.translateY / 20;

frameObject.matrix = matrix;
}
Expand Down Expand Up @@ -556,8 +556,8 @@ class SWFLiteExporter
if (placeTag.matrix != null)
{
var matrix = placeTag.matrix.matrix;
matrix.tx *= (1 / 20);
matrix.ty *= (1 / 20);
matrix.tx = placeTag.matrix.translateX / 20;
matrix.ty = placeTag.matrix.translateY / 20;

frameObject.matrix = matrix;
}
Expand Down Expand Up @@ -806,10 +806,10 @@ class SWFLiteExporter
}

symbol.records = records;

var matrix = tag.textMatrix.matrix;
matrix.tx *= (1 / 20);
matrix.ty *= (1 / 20);
matrix.tx = tag.textMatrix.translateX / 20;
matrix.ty = tag.textMatrix.translateY / 20;

symbol.matrix = matrix;

Expand Down
36 changes: 27 additions & 9 deletions src/swf/exporters/swflite/SpriteSymbol.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import swf.exporters.swflite.timeline.Frame;
import swf.exporters.swflite.timeline.SymbolTimeline;
import openfl.display.DisplayObject;
import openfl.display.MovieClip;
import openfl.display.Sprite;
import openfl.geom.Rectangle;

import #if (haxe_ver >= 4.2) Std.isOfType #else Std.is as isOfType #end;

#if !openfl_debug
@:fileXml('tags="haxe,release"')
@:noDebug
#end
@:access(openfl.display.MovieClip)
class SpriteSymbol extends SWFSymbol
{
public var baseClassName:String;
Expand All @@ -27,7 +29,15 @@ class SpriteSymbol extends SWFSymbol
frames = new Array<Frame>();
}

private function __constructor(movieClip:MovieClip):Void
private function __spriteConstructor(sprite:Sprite):Void
{
if (!isOfType(sprite, MovieClip))
throw "expected movieclip";

__movieClipConstructor(cast sprite);
}

private function __movieClipConstructor(movieClip:MovieClip):Void
{
var timeline = new SymbolTimeline(swf, this);
#if flash
Expand All @@ -38,11 +48,21 @@ class SpriteSymbol extends SWFSymbol
movieClip.scale9Grid = scale9Grid;
}

private override function __createObject(swf:SWFLite):MovieClip
private inline function __setConstructor()
{
#if (!macro && !flash)
MovieClip.__constructor = __constructor;
@:privateAccess
#if (openfl <= "9.1.0")
MovieClip.__constructor = __movieClipConstructor;
#else
Sprite.__constructor = __spriteConstructor;
#end
#end
}

private override function __createObject(swf:SWFLite):MovieClip
{
__setConstructor();
this.swf = swf;

#if flash
Expand Down Expand Up @@ -97,7 +117,7 @@ class SpriteSymbol extends SWFSymbol
}

#if flash
if (!#if (haxe_ver >= 4.2) Std.isOfType #else Std.is #end (movieClip, flash.display.MovieClip.MovieClip2))
if (!isOfType(movieClip, flash.display.MovieClip.MovieClip2))
{
movieClip.scale9Grid = scale9Grid;
}
Expand All @@ -108,15 +128,13 @@ class SpriteSymbol extends SWFSymbol

private override function __init(swf:SWFLite):Void
{
#if (!macro && !flash)
MovieClip.__constructor = __constructor;
#end
__setConstructor();
this.swf = swf;
}

private override function __initObject(swf:SWFLite, instance:DisplayObject):Void
{
this.swf = swf;
__constructor(cast instance);
__movieClipConstructor(cast instance);
}
}
17 changes: 17 additions & 0 deletions src/swf/runtime/MovieClip.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class MovieClip extends #if flash openfl.display.MovieClip.MovieClip2 #else open
{
super();
attachTimeline(new MovieClipTimeline(data));

#if !flash
__enterFrame(0);
#end
}
}

Expand Down Expand Up @@ -218,7 +222,20 @@ class MovieClipTimeline extends Timeline
}

#if !flash
setChildField(displayObject);
#end
}

@:noCompletion private inline function setChildField(displayObject:DisplayObject)
{
#if (openfl_dynamic && haxe_ver < "4.0.0")
Reflect.setField(movieClip, displayObject.name, displayObject);
#else
// Check that the type allows this field
if (Type.getInstanceFields(Type.getClass(movieClip)).indexOf(displayObject.name) != -1)
{
Reflect.setField(movieClip, displayObject.name, displayObject);
}
#end
}

Expand Down