apache / royale-asjs

Apache Royale ASJS
Apache License 2.0
372 stars 116 forks source link

Generated ${body} has an invalid class reference on release #240

Closed jgranick closed 6 years ago

jgranick commented 6 years ago

When building for debug, ${head} and ${body} generate and run properly, but on release the ${body} contains a class name that has been changed during release optimizations

C:\Development\Haxe\starling\samples\demo_npm\as3>npm start -s
MXMLJSC
+royalelib=C:\Development\Haxe\starling\samples\demo_npm\as3\node_modules\@apache-royale\royale-js\royale-asjs\frameworks
+configname=js
--output=./
--html-template=template.html
--source-path+=src
--external-library-path+=node_modules/openfl/dist/openfl.swc
--external-library-path+=node_modules/starling-framework/dist/starling.swc
--targets=js
src/Main.as

Both debug and release configurations generate new Main() for the body in the HTML template, but the Main class is renamed on release, and is not available in the window

jgranick commented 6 years ago

Is there an argument to choose a different entry point (such as MyClass.start ()) rather than creating a new instance? Is this only possible avoiding the use of ${body} in the template?

aharui commented 6 years ago

What does Main.js look like? It should have a goog.ExportSymbol. So even when the class is renamed, the Google Closure LIbrary builds an alias to the class so that MyClass should still be present at runtime.

We don't have any options for the entry point, but we could add them or associate them with a target.

jgranick commented 6 years ago

Sorry, here's the generated Main.js file:

var aa='Constants',f='DejaVu Sans',ba='MainMenu',ca='Type Coercion failed',g='Ubuntu',da='assets/textures/1x/background.jpg',h='class',k='onAddedToStage',l='onButtonTriggered',ea='onDelayButtonTriggered',fa='onRemovedFromStage',m='onStartButtonTriggered',q='onTouch',ha='org.apache.royale.utils.Language',ia='scenes.AnimationScene',ja='scenes.BenchmarkScene',ka='scenes.BlendModeScene',la='scenes.CustomHitTestScene',ma='scenes.FilterScene',na='scenes.MaskScene',oa='scenes.MovieScene',pa='scenes.RenderTextureScene',
qa='scenes.Sprite3DScene',ra='scenes.TextScene',sa='scenes.TextureScene',ta='scenes.TouchScene',ua='starling_rocket',va='utils.MenuButton',wa='utils.ProgressBar',xa='utils.RoundButton',ya='utils.TouchSheet',r=this;function za(){}function Aa(a,b,c){return a.call.apply(a.bind,arguments)}
function Ba(a,b,c){if(!a)throw Error();if(2<arguments.length){var d=Array.prototype.slice.call(arguments,2);return function(){var c=Array.prototype.slice.call(arguments);Array.prototype.unshift.apply(c,d);return a.apply(b,c)}}return function(){return a.apply(b,arguments)}}function Ca(a,b,c){Ca=Function.prototype.bind&&-1!=Function.prototype.bind.toString().indexOf('native code')?Aa:Ba;return Ca.apply(null,arguments)}
function t(a,b){a=a.split('.');var c=r;a[0]in c||!c.execScript||c.execScript('var '+a[0]);for(var d;a.length&&(d=a.shift());)a.length||void 0===b?c=c[d]&&c[d]!==Object.prototype[d]?c[d]:c[d]={}:c[d]=b}function v(a,b){function c(){}c.prototype=b.prototype;a.S=b.prototype;a.prototype=new c;a.prototype.constructor=a;a.kd=function(a,c,n){for(var d=Array(arguments.length-2),e=2;e<arguments.length;e++)d[e-2]=arguments[e];return b.prototype[c].apply(a,d)}};var Da=String.prototype.trim?function(a){return a.trim()}:function(a){return a.replace(/^[\s\xa0]+|[\s\xa0]+$/g,'')};function Ea(a,b){return a<b?-1:a>b?1:0};function Fa(a,b){var c=Ga;return Object.prototype.hasOwnProperty.call(c,a)?c[a]:c[a]=b(a)};var w;a:{var Ha=r.navigator;if(Ha){var Ia=Ha.userAgent;if(Ia){w=Ia;break a}}w=''};var Ja=-1!=w.indexOf('Opera'),x=-1!=w.indexOf('Trident')||-1!=w.indexOf('MSIE'),Ka=-1!=w.indexOf('Edge'),La=-1!=w.indexOf('Gecko')&&!(-1!=w.toLowerCase().indexOf('webkit')&&-1==w.indexOf('Edge'))&&!(-1!=w.indexOf('Trident')||-1!=w.indexOf('MSIE'))&&-1==w.indexOf('Edge'),Ma=-1!=w.toLowerCase().indexOf('webkit')&&-1==w.indexOf('Edge'),Na;
a:{var Oa='',Pa=function(){var a=w;if(La)return/rv\:([^\);]+)(\)|;)/.exec(a);if(Ka)return/Edge\/([\d\.]+)/.exec(a);if(x)return/\b(?:MSIE|rv)[: ]([^\);]+)(\)|;)/.exec(a);if(Ma)return/WebKit\/(\S+)/.exec(a);if(Ja)return/(?:Version)[ \/]?(\S+)/.exec(a)}();Pa&&(Oa=Pa?Pa[1]:'');if(x){var y,Qa=r.document;y=Qa?Qa.documentMode:void 0;if(null!=y&&y>parseFloat(Oa)){Na=String(y);break a}}Na=Oa}var Ga={};
function z(a){return Fa(a,function(){for(var b=0,c=Da(String(Na)).split('.'),d=Da(String(a)).split('.'),e=Math.max(c.length,d.length),n=0;0==b&&n<e;n++){var p=c[n]||'',u=d[n]||'';do{p=/(\d*)(\D*)(.*)/.exec(p)||['','','',''];u=/(\d*)(\D*)(.*)/.exec(u)||['','','',''];if(0==p[0].length&&0==u[0].length)break;b=Ea(0==p[1].length?0:parseInt(p[1],10),0==u[1].length?0:parseInt(u[1],10))||Ea(0==p[2].length,0==u[2].length)||Ea(p[2],u[2]);p=p[3];u=u[3]}while(0==b)}return 0<=b})};x&&z('9');!Ma||z('528');La&&z('1.9b')||x&&z('8')||Ja&&z('9.5')||Ma&&z('528');La&&!z('8')||x&&z('9');(function(){if(!r.addEventListener||!Object.defineProperty)return!1;var a=!1,b=Object.defineProperty({},'passive',{get:function(){a=!0}});r.addEventListener('test',za,b);r.removeEventListener('test',za,b);return a})();function A(){starling.display.C.call(this);this.N=new B('Back',88,50);this.N.x=C-this.N.width/2;this.N.y=480-this.N.height+4;this.N.name='backButton';this.N.mc.y-=3;this.N.gc();this.g(this.N)}v(A,starling.display.C);t('scenes.Scene',A);A.prototype.i={names:[{name:'Scene',o:'scenes.Scene',kind:h}]};function Ra(){A.call(this);var a=new starling.display.Image(D.assets.B('flight_00'));a.x=-20;a.y=0;this.g(a);a=new starling.display.Image(D.assets.B('flight_04'));a.x=90;a.y=85;this.g(a);a=new starling.display.Image(D.assets.B('flight_08'));a.x=100;a.y=-60;this.g(a);try{var b=D.assets.Ad('compressed_texture'),c=starling.qb.Hb.xd(b),d=new starling.display.Image(c);d.x=C-d.width/2;d.y=280;this.g(d)}catch(e){b=new starling.text.A(220,128,'ATF textures are not fully supported in non Flash/Air targets.'),
b.format.font=f,b.format.size=14,b.x=C-b.width/2,b.y=280,this.g(b)}}v(Ra,A);t(sa,Ra);Ra.prototype.i={names:[{name:'TextureScene',o:sa,kind:h}]};function E(){A.call(this);this.Ua={};this.ka=new starling.qb.Xc(320,435);this.sa=new starling.display.Image(this.ka);this.sa.addEventListener(starling.h.TouchEvent.ra,F(this.ha,this,q));this.g(this.sa);this.D=new starling.display.Image(D.assets.B('brush'));this.D.ec=this.D.width/2;this.D.fc=this.D.height/2;this.D.ya=starling.display.L.Ba;var a=new starling.text.A(256,128,'Touch the screen\nto draw!');a.format.font=f;a.format.size=24;a.x=C-a.width/2;a.y=G-a.height/2;this.ka.Vb(a);a.m();this.s=new B('Mode: Draw');
this.s.x=C-this.s.width/2;this.s.y=15;this.s.addEventListener(starling.h.Event.M,F(this.R,this,l));this.g(this.s)}v(E,A);t(pa,E);E.prototype.ha=function(a){var b=this;this.ka.qd(function(){var c=H(a.Xb(b.sa),Array),d;for(d in c){var e=c[d];e.hb==starling.h.T.tb&&(b.Ua[e.id]=2147483648*Math.random()>>>0);if(e.hb!=starling.h.T.Bb&&e.hb!=starling.h.T.Pa){var n=Number(b.Ua[e.id]);e=e.Ha(b.sa);b.D.x=e.x;b.D.y=e.y;b.D.color=n;b.D.rotation=Math.random()*Math.PI*2;b.ka.Vb(b.D);b.Wd()}}})};
E.prototype.R=function(){this.D.ya==starling.display.L.Ba?(this.D.ya=starling.display.L.Ab,this.s.text='Mode: Erase'):(this.D.ya=starling.display.L.Ba,this.s.text='Mode: Draw')};E.prototype.m=function(){this.ka.m();E.S.m.apply(this)};E.prototype.dispose=E.prototype.m;E.prototype.i={names:[{name:'RenderTextureScene',o:pa,kind:h}]};function I(a){a='undefined'!==typeof a?a:null;starling.display.C.call(this);this.addEventListener(starling.h.TouchEvent.ra,F(this.ha,this,q));null!=a&&(a.x=a.width/-2,a.y=a.height/-2,this.g(a))}v(I,starling.display.C);t(ya,I);
I.prototype.ha=function(a){var b=H(a.Xb(this,starling.h.T.Db),Array);if(1==b.length)b=b[0].Bd(this.parent),this.x+=b.x,this.y+=b.y;else if(2==b.length){var c=b[0],d=b[1];b=c.Ha(this.parent);var e=c.Ia(this.parent),n=d.Ha(this.parent),p=d.Ia(this.parent),u=b.lc(n);e=e.lc(p);p=Math.atan2(u.y,u.x)-Math.atan2(e.y,e.x);c=c.Ia(this);d=d.Ia(this);this.ec=.5*(c.x+d.x);this.fc=.5*(c.y+d.y);this.x=.5*(b.x+n.x);this.y=.5*(b.y+n.y);this.rotation+=p;b=u.length/e.length;this.oa*=b;this.mb*=b}a=a.za(this,starling.h.T.Pa);
null!=a&&2==a.Zd&&this.parent.g(this)};I.prototype.m=function(){this.removeEventListener(starling.h.TouchEvent.ra,F(this.ha,this,q));I.S.m.apply(this)};I.prototype.dispose=I.prototype.m;I.prototype.i={names:[{name:'TouchSheet',o:ya,kind:h}]};function J(){A.call(this);this.Wa=[starling.ba.ia.LINEAR,starling.ba.ia.Bc,starling.ba.ia.Cc,starling.ba.ia.Dc,starling.ba.ia.Ec];this.v=new B('Start animation');this.v.addEventListener(starling.h.Event.M,F(this.na,this,m));this.v.x=C-this.v.width/2;this.v.y=20;this.g(this.v);this.W=new B('Delayed call');this.W.addEventListener(starling.h.Event.M,F(this.eb,this,ea));this.W.x=this.v.x;this.W.y=this.v.y+40;this.g(this.W);this.X=new starling.display.Image(D.assets.B('starling_front'));this.g(this.X);
Sa(this);this.P=new starling.text.A(320,30);this.P.format.size=20;this.P.format.bold=!0;this.P.format.font=f;this.P.y=this.W.y+40;this.P.alpha=0;this.g(this.P)}v(J,A);t(ia,J);function Sa(a){a.X.x=20;a.X.y=100;a.X.oa=a.X.mb=1;a.X.rotation=0}
J.prototype.na=function(){var a=this;this.v.enabled=!1;Sa(this);var b=K(this.Wa.shift());this.Wa.push(b);var c=new starling.ba.Ib(this.X,2,b);c.Qb('rotation',starling.w.Eb.Tb(90));c.moveTo(300,360);c.Ud(.5);c.cb=function(){a.v.enabled=!0};starling.l.j.current.J.add(c);this.P.text=b;this.P.alpha=1;b=new starling.ba.Ib(this.P,2,starling.ba.ia.Ac);b.Qb('alpha',0);starling.l.j.current.J.add(b)};
J.prototype.eb=function(){var a=this;this.W.enabled=!1;starling.l.j.current.J.$a(F(this.Za,this,'colorizeEgg'),1,[!0]);starling.l.j.current.J.$a(F(this.Za,this,'colorizeEgg'),2,[!1]);starling.l.j.current.J.$a(function(){a.W.enabled=!0},2)};J.prototype.Za=function(a){this.X.color=Number(a?15368736:starling.w.xb.Jb)};J.prototype.m=function(){this.v.removeEventListener(starling.h.Event.M,F(this.na,this,m));this.W.removeEventListener(starling.h.Event.M,F(this.eb,this,ea));J.S.m.apply(this)};
J.prototype.dispose=J.prototype.m;J.prototype.i={names:[{name:'AnimationScene',o:ia,kind:h}]};function L(){A.call(this);this.u=new starling.display.C;this.u.x=C;this.u.y=G;this.u.rb=!1;this.Ya(this.u,0);this.ga=new starling.text.A(280,30);this.ga.format=new starling.text.dd(starling.text.Oa.MINI,2*starling.text.Oa.NATIVE_SIZE);this.ga.x=20;this.ga.y=10;this.g(this.ga);this.v=new B('Start benchmark');this.v.addEventListener(starling.h.Event.M,F(this.na,this,m));this.v.x=C-this.v.width/2;this.v.y=20;this.g(this.v);this.Fa=!1;this.fa=Ta();this.$=Ta();this.Kb=D.assets.B('benchmark_object');this.addEventListener(starling.h.Event.zb,
F(this.fb,this,'onEnterFrame'))}v(L,A);t(ja,L);L.prototype.Ca=0;L.prototype.ea=0;L.prototype.aa=0;L.prototype.wa=0;L.prototype.m=function(){this.removeEventListener(starling.h.Event.zb,F(this.fb,this,'onEnterFrame'));this.v.removeEventListener(starling.h.Event.M,F(this.na,this,m));var a=this.$,b;for(b in a){var c=a[b];c&&F(c.m,c,'dispose')&&c.m()}L.S.m.apply(this)};L.prototype.dispose=L.prototype.m;
L.prototype.na=function(){this.v.visible=!1;this.Fa=!0;this.aa=starling.l.j.current.ac.frameRate;this.wa=this.ea=this.Ca=0;0>=this.aa&&(this.aa=60);for(var a=0;10>a;a++)this.fa[a]=1/this.aa;null!=this.I&&(this.I.ib(!0),this.I=null)};
L.prototype.fb=function(a,b){if(this.Fa){this.Ca++;this.u.rotation+=.5*a.Nd;for(a=this.fa[10]=0;10>a;a++)this.fa[a]+=b;b=10/this.fa.shift();if(0==this.wa)if(b<.985*this.aa)this.ea++,100==this.ea&&(this.wa=1);else{a=1/this.u.scale;for(var c=0;16>c;c++){if(0==this.$.length){var d=new starling.display.Image(this.Kb);d.Pb();d.Pd=!1}else d=this.$.pop();var e=(100+100*Math.random())*a,n=Math.random()*Math.PI*2;d.x=Math.cos(n)*e;d.y=Math.sin(n)*e;d.rotation=n+Math.PI/2;d.scale=a;this.u.g(d)}this.u.scale*=
.99;this.ea=0}if(1==this.wa)if(b>.99*this.aa){if(this.ea--,0==this.ea)for(this.Fa=!1,this.v.visible=!0,b=this.u.Ka,a=starling.w.bd.format('Result:\n{0} objects\nwith {1} fps',[b,starling.l.j.current.ac.frameRate]),a.replace(/\u000a/g,' '),this.I=new starling.text.A(240,200,a),this.I.format.font=f,this.I.format.size=30,this.I.x=C-this.I.width/2,this.I.y=G-this.I.height/2,this.g(this.I),this.u.scale=1,this.fa.length=0,this.ga.text='',--b;0<=b;)a=this.u.hc(b),this.$[this.$.length]=a,--b}else{b=1;a=this.u.Ka;
b>=a&&(b=a);for(a=0;a<b;a++)c=this.u.hc(this.u.Ka-1),this.$[this.$.length]=c;this.u.scale/=.9993720513}0==this.Ca%Math.floor(this.aa/4)&&(this.ga.text=this.u.Ka+' objects')}};L.prototype.i={names:[{name:'BenchmarkScene',o:ja,kind:h}]};function M(){A.call(this);this.la()}v(M,A);t(ra,M);
M.prototype.la=function(){var a=new starling.text.A(300,80,'TextFields can have a border and a color. They can be aligned in different ways, ...');a.format.Ma(g,19,209817);a.x=a.y=10;a.border=!0;this.g(a);var b=new starling.text.A(145,80,'... e.g.\ntop-left ...');b.format.Ma(g,19,10053171);b.format.ab=starling.w.ca.Lc;b.format.verticalAlign=starling.w.ca.Sa;b.x=10;b.y=a.y+a.height+10;b.border=!0;this.g(b);a=new starling.text.A(145,80,'... or\nbottom right ...');a.format.Ma(g,19,2129952);a.format.ab=
starling.w.ca.Uc;a.format.verticalAlign=starling.w.ca.Sa;a.border=!0;a.x=20+b.width;a.y=b.y;this.g(a);a=new starling.text.A(300,80,"... or centered. Embedded fonts are detected automatically and \x3cfont color\x3d'#208080'\x3esupport\x3c/font\x3e \x3cfont color\x3d'#996633'\x3ebasic\x3c/font\x3e \x3cfont color\x3d'#333399'\x3eHTML\x3c/font\x3e \x3cfont color\x3d'#208020'\x3eformatting\x3c/font\x3e.");a.format.Ma(g,19);a.x=10;a.y=b.y+b.height+10;a.border=!0;a.Gd=!0;this.g(a);b=new starling.text.A(300,
150,'It is very easy to use Bitmap fonts,\nas well!');b.format.font='Desyrel';b.format.size=starling.text.Oa.NATIVE_SIZE;b.format.color=starling.w.xb.Jb;b.x=10;b.y=a.y+a.height+10;this.g(b)};M.prototype.i={names:[{name:'TextScene',o:ra,kind:h}]};function D(){starling.display.C.call(this)}var Ua;v(D,starling.display.C);t('Game',D);D.prototype.start=function(a){Ua=a;this.g(new starling.display.Image(a.B('background')));Va(this);this.addEventListener(starling.h.Event.M,F(this.R,this,l));this.K.addEventListener(starling.h.KeyboardEvent.Kc,F(this.cc,this,'onKey'))};D.prototype.start=D.prototype.start;function Va(a){openfl.pb.cd.zd();null==a.va&&(a.va=new N);a.g(a.va)}
D.prototype.cc=function(a){a.keyCode==openfl.nc.Cb.Zc?starling.l.j.current.Na=!starling.l.j.current.Na:a.keyCode==openfl.nc.Cb.ed&&starling.l.j.current.context.m()};D.prototype.R=function(a){a=H(a.target,starling.display.qa);'backButton'==a.name?(this.ua.ib(!0),this.ua=null,Va(this)):null==this.ua&&(this.ua=H(new this.va.sceneClasses[a.name],A),this.va.ib(),this.g(this.ua))};Object.defineProperties(D,{assets:{get:function(){return Ua}}});D.prototype.i={names:[{name:'Game',o:'Game',kind:h}]};function O(){this.Ta=[starling.display.L.Ba,starling.display.L.Mc,starling.display.L.Yc,starling.display.L.oc,starling.display.L.Ab,starling.display.L.NONE];A.call(this);this.s=new B('Switch Mode');this.s.x=C-this.s.width/2;this.s.y=15;this.s.addEventListener(starling.h.Event.M,F(this.R,this,l));this.g(this.s);this.F=new starling.display.Image(D.assets.B(ua));this.F.x=Math.round(C-this.F.width/2);this.F.y=170;this.g(this.F);this.G=new starling.text.A(300,32);this.G.format.size=19;this.G.format.font=
f;this.G.x=10;this.G.y=330;this.g(this.G);this.R()}v(O,A);t(ka,O);O.prototype.R=function(){var a=K(this.Ta.shift());this.Ta.push(a);this.G.text=a;this.F.ya=a};O.prototype.i={names:[{name:'BlendModeScene',o:ka,kind:h}]};function Wa(){A.call(this);var a=new starling.text.A(300,25,'[use Ctrl/Cmd \x26 Shift to simulate multi-touch]');a.format.font=f;a.x=a.y=10;this.g(a);a=new I(new starling.display.Image(D.assets.B('starling_sheet')));a.x=C;a.y=G;a.rotation=starling.w.Eb.Tb(10);this.g(a)}v(Wa,A);t(ta,Wa);Wa.prototype.i={names:[{name:'TouchScene',o:ta,kind:h}]};function P(){A.call(this);var a=D.assets.B('gamua-logo'),b=a.width/2,c=Q(a,16711680);c.z=-b;var d=Q(a,65280);d.La=Math.PI;d.z=b;var e=Q(a,255);e.y=-b;e.La=Math.PI/-2;var n=Q(a,16776960);n.y=b;n.La=Math.PI/2;var p=Q(a,16711935);p.x=-b;p.lb=Math.PI/2;a=Q(a,65535);a.x=b;a.lb=Math.PI/-2;b=new starling.display.Gb;b.g(c);b.g(d);b.g(e);b.g(n);b.g(p);b.g(a);this.V=b;this.V.x=C;this.V.y=G;this.V.z=100;this.g(this.V);this.addEventListener(starling.h.Event.pa,F(this.start,this,'start'));this.addEventListener(starling.h.Event.Qa,
F(this.stop,this,'stop'))}v(P,A);t(qa,P);P.prototype.start=function(){starling.l.j.current.J.sb(this.V,6,{La:2*Math.PI,kb:0});starling.l.j.current.J.sb(this.V,7,{lb:2*Math.PI,kb:0});starling.l.j.current.J.sb(this.V,8,{Sd:2*Math.PI,kb:0})};P.prototype.stop=function(){starling.l.j.current.J.Rd(this.V)};function Q(a,b){b='undefined'!==typeof b?b:16777215;a=new starling.display.Image(a);a.color=b;a.Pb();b=new starling.display.Gb;b.g(a);return b}
P.prototype.jb=function(a){a.pushState();a.state.pd=openfl.Ub.yc.BACK;P.S.jb.apply(this,[a]);a.Qd()};P.prototype.render=P.prototype.jb;P.prototype.i={names:[{name:'Sprite3DScene',o:qa,kind:h}]};function R(){A.call(this);var a=D.assets.Dd('flight');this.Y=new starling.display.Pc(a,15);a=D.assets.Cd('wing_flap');this.Y.Vd(2,a);this.Y.x=C-this.Y.width/2;this.Y.y=G-this.Y.height/2;this.g(this.Y);this.addEventListener(starling.h.Event.pa,F(this.ma,this,k));this.addEventListener(starling.h.Event.Qa,F(this.gb,this,fa))}v(R,A);t(oa,R);R.prototype.ma=function(){starling.l.j.current.J.add(this.Y)};R.prototype.gb=function(){starling.l.j.current.J.remove(this.Y)};
R.prototype.m=function(){this.removeEventListener(starling.h.Event.Qa,F(this.gb,this,fa));this.removeEventListener(starling.h.Event.pa,F(this.ma,this,k));R.S.m.apply(this)};R.prototype.dispose=R.prototype.m;R.prototype.i={names:[{name:'MovieScene',o:oa,kind:h}]};function B(a,b,c){b='undefined'!==typeof b?b:128;c='undefined'!==typeof c?c:32;starling.display.qa.call(this,D.assets.B('button_normal'),a);this.$d.font=f;new openfl.Ga.Ra(12.5,12.5,20,20);this.width=b;this.height=c}v(B,starling.display.qa);t(va,B);B.prototype.i={names:[{name:'MenuButton',o:va,kind:h}]};function S(){A.call(this);this.s=new B('Switch Filter');this.s.x=C-this.s.width/2;this.s.y=15;this.s.addEventListener(starling.h.Event.M,F(this.R,this,l));this.g(this.s);this.F=new starling.display.Image(D.assets.B(ua));this.F.x=C-this.F.width/2;this.F.y=170;this.g(this.F);this.G=new starling.text.A(300,32);this.G.format.font=f;this.G.format.size=19;this.G.x=10;this.G.y=330;this.g(this.G);this.H=[['Identity',new starling.filters.Gc],['Blur',new starling.filters.uc],['Drop Shadow',new starling.filters.yb],
['Glow',new starling.filters.Ic]];var a=starling.l.j.current.nd,b=new openfl.display.ub(this.F.width*a,this.F.height*a,!1);b.Od(20*a,20*a,3,5,!1,!0);this.Va=starling.qb.Hb.yd(b,!1,!1,a);a=new starling.filters.zc(this.Va,openfl.display.vb.Sc,openfl.display.vb.Hc,25,25);this.H.push(['Displacement Map',a]);a=new starling.filters.da;a.Fd();this.H.push(['Invert',a]);a=new starling.filters.da;a.Ob(-1);this.H.push(['Grayscale',a]);a=new starling.filters.da;a.Ob(1);this.H.push(['Saturation',a]);a=new starling.filters.da;
a.jd(.75);this.H.push(['Contrast',a]);a=new starling.filters.da;a.hd(-.25);this.H.push(['Brightness',a]);a=new starling.filters.da;a.Nb(1);this.H.push(['Hue',a]);a=new starling.filters.Fc([a,new starling.filters.yb]);this.H.push(['Hue + Shadow',a]);this.R()}v(S,A);t(ma,S);S.prototype.m=function(){this.Va.m();S.S.m.apply(this)};S.prototype.dispose=S.prototype.m;S.prototype.R=function(){var a=this.H.shift();this.H.push(a);this.G.text=K(a[0]);this.F.filter=a[1]};
S.prototype.i={names:[{name:'FilterScene',o:ma,kind:h}]};function T(){}var U,V;t(ha,T);var Xa=[],Ya=String.fromCharCode(0);function H(a,b,c){c='undefined'!==typeof c?c:null;b=Za(a,b);if(!b&&void 0!==c&&c)throw a=TypeError?new TypeError(ca):Error(ca),a;return b?a:null}t('org.apache.royale.utils.Language.as',H);t('org.apache.royale.utils.Language._int',function(a){return a>>0});function K(a){return null==a?null:a.toString()}t('org.apache.royale.utils.Language.string',K);
function Za(a,b){if(null==a||null==b)return!1;if(a instanceof b||b===Object)return!0;if('string'===typeof a)return b===String;if('number'===typeof a)return b===Number;if('boolean'===typeof a)return b===Boolean;if(b===Array)return Array.isArray(a);if(void 0===a.i)return!1;if(a.i.Ja&&$a(a,b))return!0;a=a.constructor;if(a=a.S)for(;a&&a.i;){if(a.i.Ja&&$a(a,b))return!0;a=a.constructor;a=a.S}return!1}t('org.apache.royale.utils.Language.is',Za);
function $a(a,b){var c=a.i.Ja;for(a=c.length-1;-1<a;a--)if(c[a]===b||c[a].prototype.i.Ja&&$a(c[a].prototype,b))return!0;return!1}T.prototype.bb=function(a){return'function'===typeof a&&a.prototype&&a.prototype.constructor===a};T.prototype.isClass=T.prototype.bb;T.prototype.Rb=function(a){return this.bb(a)?a:null};T.prototype.asClass=T.prototype.Rb;t('org.apache.royale.utils.Language.trace',function(){});t('org.apache.royale.utils.Language.uint',function(a){return a>>>0});
function F(a,b,c){if(b.hasOwnProperty(c))return b[c];a=Ca(a,b);Object.defineProperty(b,c,{value:a});return a}t('org.apache.royale.utils.Language.closure',F);t('org.apache.royale.utils.Language.sortOn',function(a,b,c){c='undefined'!==typeof c?c:0;Za(b,Array)?U=H(b,Array):(Xa[0]=b,U=Xa);if(Za(c,Array)){b=0;for(var d in c)b|=c[d]}else b=H(c,Number);V=0<(2&b)?-1:1;b&16?a.sort(ab):b&1?a.sort(bb):a.sort(cb)});
function bb(a,b){var c=U,d;for(d in c){var e=c[d];e=Number((a[e]||Ya).toString().toLowerCase().localeCompare((b[e]||Ya).toString().toLowerCase()));if(0!=e)return e*V}return 0}function cb(a,b){var c=U,d;for(d in c){var e=c[d];e=Number((a[e]||Ya).toString().localeCompare((b[e]||Ya).toString()));if(0!=e)return e*V}return 0}function ab(a,b){var c=U,d;for(d in c){var e=c[d];if(a[e]>b[e])return V;if(a[e]<b[e])return-V}return 0}
function Ta(a,b){a='undefined'!==typeof a?a:0;b='undefined'!==typeof b?b:null;var c=[],d=null;'int'==b||'uint'==b||'Number'==b?d=0:'String'==b&&(d='');for(b=0;b<a;b++)c.push(d);return c}t('org.apache.royale.utils.Language.Vector',Ta);T.prototype.i={names:[{name:'Language',o:ha,kind:h}]};function N(){this.Ea=[];starling.display.C.call(this);this.la()}v(N,starling.display.C);t(ba,N);
N.prototype.la=function(){var a=new starling.display.Image(D.assets.B('logo'));this.g(a);a=[['Textures',Ra],['Multitouch',Wa],['TextFields',M],['Animations',J],['Custom hit-test',db],['Movie Clip',R],['Filters',S],['Blend Modes',O],['Render Texture',E],['Benchmark',L],['Masks',W],['Sprite 3D',P]];var b=0;for(e in a){var c=a[e],d=c[1];c=new B(K(c[0]));c.height=42;c.gc();c.x=0==b%2?28:167;c.y=155+46*(b/2>>0);c.name=String(this.Ea.length);this.Ea.push(d);this.g(c);0!=a.length%2&&1==b%2&&(c.y+=24);++b}var e=
new starling.text.A(310,64,starling.l.j.current.context.ud);e.format.font=f;e.format.size=10;e.format.verticalAlign=starling.w.ca.tc;e.x=5;e.y=475-e.height;e.addEventListener(starling.h.TouchEvent.ra,F(this.bc,this,'onInfoTextTouched'));this.Ya(e,0)};N.prototype.bc=function(a){null!=a.za(this,starling.h.T.Pa)&&(starling.l.j.current.Na=!starling.l.j.current.Na)};N.prototype.Zb=function(){return this.Ea};Object.defineProperties(N.prototype,{sceneClasses:{get:N.prototype.Zb}});
N.prototype.i={names:[{name:ba,o:ba,kind:h}]};function db(){A.call(this);var a=new starling.text.A(300,100,"Pushing the bird only works when the touch occurs within a circle.This can be accomplished by overriding the method 'hitTest'.");a.format.font=f;a.x=a.y=10;a.format.verticalAlign=starling.w.ca.Sa;a.format.ab=starling.w.ca.vc;this.g(a);a=new X(D.assets.B('starling_round'));a.x=C-a.width/2;a.y=150;this.g(a)}v(db,A);t(la,db);db.prototype.i={names:[{name:'CustomHitTestScene',o:la,kind:h}]};function W(){A.call(this);this.ta=new starling.display.C;this.g(this.ta);var a=starling.l.j.current.K.ob,b=new starling.display.Rc(a,starling.l.j.current.K.nb);b.alpha=0;this.Ya(b,0);b=new starling.display.Image(D.assets.B('flight_00'));b.x=(a-b.width)/2;b.y=80;this.ta.g(b);var c=new starling.filters.da;c.Nb(-.5);b.filter=c;b=new starling.text.A(256,128,'Move the mouse (or a finger) over the screen to move the mask.');b.format.font=f;b.x=(a-b.width)/2;b.y=260;b.format.size=20;this.ta.g(b);this.ja=
eb();this.ja.alpha=.1;this.ja.rb=!1;this.g(this.ja);this.Da=eb();this.ta.Jd=this.Da;this.addEventListener(starling.h.TouchEvent.ra,F(this.ha,this,q))}v(W,A);t(na,W);W.prototype.ha=function(a){var b=a.za(this,starling.h.T.Bb);null==b&&(b=a.za(this,starling.h.T.tb));null==b&&(b=a.za(this,starling.h.T.Db));null!=b&&(a=b.Ha(this),this.Da.x=this.ja.x=a.x,this.Da.y=this.ja.y=a.y)};function eb(){var a=new starling.display.wc;a.Sb(15368736);a.rd(0,0,100);a.Wb();return a}
W.prototype.i={names:[{name:'MaskScene',o:na,kind:h}]};function Y(){openfl.display.C.call(this);null!=this.K?this.start():this.addEventListener(starling.h.Event.pa,F(this.ma,this,k))}v(Y,openfl.display.C);t('Demo',Y);Y.prototype.ma=function(){this.removeEventListener(starling.h.Event.pa,F(this.ma,this,k));this.K.Td=openfl.display.ad.Qc;this.start()};
Y.prototype.start=function(){var a=this;starling.l.j.Kd=!0;this.O=new starling.l.j(D,this.K,null,null,openfl.Ub.xc.pc,'auto');this.O.K.ob=320;this.O.K.nb=480;this.O.vd=openfl.pb.wb.isDebugger;this.O.Yd=!0;this.O.Xd=!0;this.O.addEventListener(starling.h.Event.Vc,function(){fb(a,F(a.kc,a,'startGame'))});this.K.addEventListener(starling.h.Event.Tc,F(this.dc,this,'onResize'),!1,starling.w.Oc.INT_MAX_VALUE,!0);this.O.start();openfl.display.ub.Hd(da).cb()};
function fb(a){(new starling.w.rc).ae=openfl.pb.wb.isDebugger;var b=new openfl.w.sc;b.Xa('assets/textures/1x/atlas.png');b.Mb('assets/textures/1x/atlas.xml');b.Xa('assets/fonts/1x/desyrel.png');b.Mb('assets/fonts/1x/desyrel.fnt');b.Xa(da);b.gd(['assets/audio/wing_flap.ogg','assets/audio/wing_flap.mp3']);b.fd('assets/textures/1x/compressed_texture.atf');b.Lb(f);b.Lb(g);openfl.w.qc.Id(b).cb().Md(function(b,d){null!=a.xa&&0<d&&(a.xa.ratio=b/d)}).Ld(function(){})}
Y.prototype.kc=function(a){H(this.O.root,D).start(a);setTimeout(F(this.ic,this,'removeElements'),150)};Y.prototype.ic=function(){null!=this.Z&&(this.removeChild(this.Z),this.Z=null);null!=this.xa&&(this.removeChild(this.xa),this.xa=null)};Y.prototype.dc=function(){var a=starling.w.Wc.wd(new openfl.Ga.Ra(0,0,320,480),new openfl.Ga.Ra(0,0,this.K.ob,this.K.nb));try{this.O.be=a}catch(b){}};Y.prototype.i={names:[{name:'Demo',o:'Demo',kind:h}]};function Z(a,b){openfl.display.C.call(this);this.la(a,b)}v(Z,openfl.display.C);t(wa,Z);Z.prototype.la=function(a,b){var c=.2*b,d=2*c;this.Z=new openfl.display.Fb;this.Z.Aa.Sb(0,.5);this.Z.Aa.td(0,0,a,b,d,d);this.Z.Aa.Wb();this.g(this.Z);a-=2*c;b-=2*c;d=new openfl.Ga.Nc;d.od(a,b,Math.PI/2);this.U=new openfl.display.Fb;this.U.Aa.ld(openfl.display.Jc.LINEAR,[15658734,11184810],[1,1],[0,255],d);this.U.Aa.sd(0,0,a,b);this.U.x=c;this.U.y=c;this.U.oa=0;this.g(this.U)};Z.prototype.Yb=function(){return this.U.oa};
Z.prototype.jc=function(a){this.U.oa=Math.max(0,Math.min(1,a))};Object.defineProperties(Z.prototype,{ratio:{get:Z.prototype.Yb,set:Z.prototype.jc}});Z.prototype.i={names:[{name:'ProgressBar',o:wa,kind:h}]};function gb(){}t(aa,gb);t('Constants.GameWidth',320);t('Constants.GameHeight',480);var C=160,G=240;gb.prototype.i={names:[{name:aa,o:aa,kind:h}]};function X(a,b,c){starling.display.qa.call(this,a,'undefined'!==typeof b?b:'','undefined'!==typeof c?c:null)}v(X,starling.display.qa);t(xa,X);X.prototype.$b=function(a){if(!this.visible||!this.rb||!this.Ed(a))return null;var b=this.md;return Math.pow(a.x-b.width/2,2)+Math.pow(a.y-b.height/2,2)<Math.pow(b.width/2-8,2)?this:null};X.prototype.hitTest=X.prototype.$b;X.prototype.i={names:[{name:'RoundButton',o:xa,kind:h}]};function hb(){var a=new openfl.display.$c(320,480,16777215,Y);H(document.getElementById('openfl-content'),HTMLDivElement).appendChild(a.element)}t('Main',hb);hb.prototype.i={names:[{name:'Main',o:'Main',kind:h}]};
//# sourceMappingURL=./Main.js.map

On further investigation, Uncaught TypeError: Cannot read property 'prototype' of undefined at runtime may be why Main is not coming through, but I'm unsure.

jgranick commented 6 years ago

I tried using paths to our @externs AS files rather than the SWC in the Starling demo, but I got this compiler error. I'm not fully sure of the cause:

Compiling file: /home/joshua/Development/Haxe/starling/samples/demo_npm/as3/bin/js-debug/openfl/display/Graphics.js
Internal error: java.lang.NullPointerException org.apache.royale.compiler.internal.codegen.js.jx.PackageFooterEmitter.collectReflectionData(PackageFooterEmitter.java:433)org.apache.royale.compiler.internal.codegen.js.jx.PackageFooterEmitter.emitClassInfo(PackageFooterEmitter.java:176)org.apache.royale.compiler.internal.codegen.js.jx.ClassEmitter.emit(ClassEmitter.java:227)org.apache.royale.compiler.internal.codegen.js.royale.JSRoyaleEmitter.emitClass(JSRoyaleEmitter.java:681)org.apache.royale.compiler.internal.codegen.as.ASBlockWalker.visitClass(ASBlockWalker.java:242)org.apache.royale.compiler.internal.visitor.as.ASNodeSwitch.handle(ASNodeSwitch.java:136)org.apache.royale.compiler.internal.visitor.as.ASNodeHandler.handle(ASNodeHandler.java:85)org.apache.royale.compiler.internal.visitor.as.BeforeAfterStrategy.handle(BeforeAfterStrategy.java:110)org.apache.royale.compiler.internal.codegen.as.ASBlockWalker.walk(ASBlockWalker.java:157)org.apache.royale.compiler.internal.codegen.js.goog.JSGoogEmitter.emitPackageContents(JSGoogEmitter.java:182)org.apache.royale.compiler.internal.codegen.as.ASBlockWalker.visitPackage(ASBlockWalker.java:230)org.apache.royale.compiler.internal.visitor.as.ASNodeSwitch.handle(ASNodeSwitch.java:132)org.apache.royale.compiler.internal.visitor.as.ASNodeHandler.handle(ASNodeHandler.java:85)org.apache.royale.compiler.internal.visitor.as.BeforeAfterStrategy.handle(BeforeAfterStrategy.java:110)org.apache.royale.compiler.internal.codegen.as.ASBlockWalker.walk(ASBlockWalker.java:157)org.apache.royale.compiler.internal.codegen.as.ASBlockWalker.visitFile(ASBlockWalker.java:209)org.apache.royale.compiler.internal.visitor.as.ASNodeSwitch.handle(ASNodeSwitch.java:128)org.apache.royale.compiler.internal.visitor.as.ASNodeHandler.handle(ASNodeHandler.java:85)org.apache.royale.compiler.internal.visitor.as.BeforeAfterStrategy.handle(BeforeAfterStrategy.java:110)org.apache.royale.compiler.internal.codegen.as.ASBlockWalker.walk(ASBlockWalker.java:157)org.apache.royale.compiler.internal.codegen.as.ASBlockWalker.visitCompilationUnit(ASBlockWalker.java:174)org.apache.royale.compiler.internal.codegen.js.JSWriter.writeTo(JSWriter.java:98)org.apache.royale.compiler.clients.MXMLJSCNative.compile(MXMLJSCNative.java:366)org.apache.royale.compiler.clients.MXMLJSCNative._mainNoExit(MXMLJSCNative.java:234)org.apache.royale.compiler.clients.MXMLJSCNative.mainNoExit(MXMLJSCNative.java:191)org.apache.royale.compiler.clients.MXMLJSC._mainNoExit(MXMLJSC.java:381)org.apache.royale.compiler.clients.MXMLJSC.mainNoExit(MXMLJSC.java:281)org.apache.royale.compiler.clients.MXMLJSC.staticMainNoExit(MXMLJSC.java:240)org.apache.royale.compiler.clients.MXMLJSC.main(MXMLJSC.java:222)
jgranick commented 6 years ago

Okay, figured out testing without using an SWC, using @externs AS3 instead. The above error occurred because the AS file had import openfl.Vector, I removed that and it compiled, and I get this error at runtime:

Uncaught TypeError: Cannot read property 'Sprite' of undefined

Perhaps something with the reference being stripped out, since it's defined externally in another script

aharui commented 6 years ago

Are you using the latest nightly build of the compiler? I'm thinking no. It would be best to get you to use the nightly so you can test out fixes we are making. I think if you are getting Royale via NPM you can

npm install http://apacheroyaleci.westus2.cloudapp.azure.com:8080/job/royale-asjs_jsonly/lastSuccessfulBuild/artifact/out/apache-royale-0.9.3-bin-js.tar.gz

The extern output from a compiler older than last week was potentially buggy, so please upgrade, generate new externs and see what you get. And post the extern file if you are still having problems.

jgranick commented 6 years ago

This still is not working properly using newer builds.

It may be something to do with the nature of trying to use external code. You can reproduce it using:

git clone https://github.com/openfl/starling
cd starling/samples/demo_npm/as3
npm install
npm start -s

That works, but builds using the "debug" configuration. Trying to build for production, it fails to build properly:

npm run build:prod -s
// start a web server at bin/js-release

By default, the project is using SWCs. If you want, you can point directly at *.as extern files by going into asconfig.json and using source-path instead of external-library-path:

        "source-path": [
            "node_modules/openfl/lib",
            "node_modules/starling-framework/lib",
            "src"
        ],

The compiler then throws an error about the AssetPostProcessor class inside starling-framework/lib/starling/assets/AssetManager.as, you can comment it out at the foot of the file.

At runtime, it fails when it tries to create an instance of a class (such as Demo) that extends an external class type (such as starling.display.Sprite). Using source-path, here's what that looks like:

/* Royale Dependency List: */
/**
 * Generated by Apache Royale Compiler from starling/display/Sprite.as
 * starling.display.Sprite
 *
 * @fileoverview
 * @externs
 *
 * @suppress {checkTypes|accessControls}
 */

var starling = {};
starling.display = {};

goog.require('starling.display.DisplayObjectContainer');

/**
 * @constructor
 * @extends {starling.display.DisplayObjectContainer}
 */
starling.display.Sprite = function() {
  starling.display.Sprite.base(this, 'constructor');
};
goog.inherits(starling.display.Sprite, starling.display.DisplayObjectContainer);

We support ES6 modules, CommonJS modules, or window references, but I don't think it's possible to use either ES6 modules or CommonJS modules from Apache Royale right now?

I think that now it is properly getting a reference to Main in the release build, but we're hitting other problems when doing a release (instead of a debug) compile with Closure.

Perhaps the Closure-based builds could be made to work with CommonJS modules, like:

var starling_display_DisplayObjectContainer = require("starling/display/DisplayObjectContainer").default;

I'm not sure if [JSModule] could support this, then we could try and use Webpack on the result that Royale generates

aharui commented 6 years ago

I tried getting the source and building it myself. It compiled with 0 errors and a pile of warnings. Then I ran the bin/js-release version. The error I got was cryptic, but upon investigating it turned out that Scene.js could not find starling.display.Sprite when setting up its prototype chain. In examining starling.swc, there are no externs files in there so nothing would prevent renaming of starling.display.Sprite to, in my case, starling.display.C. I'm out of time for tonight so I guess tomorrow I will try to find time to work from your AS Externs and see if I get a different result.

When creating an externs SWC, there is a SWF output that creates the library.swf in the SWC so the Royale compiler knows what definitions are in there, and there is a JS output that generates the .js files that Google Closure Compiler expects. Those .js files need to be packaged in the SWC in a 'folder' called 'externs'.

Royale does not generated code that will load ES6 modules or CommonJS modules at this time, but someone can certainly volunteer to write an "Emitter" that does so.

FWIW, when I debug the minified code, I know that the exported name of each class should still be in the minified JS so searching for "scenes.Scene" led me to the minified code for that class.

aharui commented 6 years ago

I just pushed changes that seem to get things to work using source-path to the externs in starling/samples/demo_npm/as3/node_modules/openfl/lib starling/samples/demo_npm/as3/node_modules/starling-framework/lib

There are 7 warnings mostly about how we handle Vector that we can deal with as a separate issue.