Re: flexjs eat json tilesets
i have do it,it is work. https://github.com/matrix3d/spriteflexjs/commit/76ecd143a3a46b199d162267d3392b47d43b1cd4#diff-c879807e920323f1f8c480753875170eR61 but if it do with the flexjs is good. -- View this message in context: http://apache-flex-development.247.n4.nabble.com/flexjs-eat-json-tilesets-tp51581p51697.html Sent from the Apache Flex Development mailing list archive at Nabble.com.
Re: flexjs eat json tilesets
On 2/23/16, 9:35 PM, "lizhi" wrote: >the flexjs just 0.6 beta. >if the 0.7 have this function is good. >it is just give my idea. >thanks your hard work It is unlikely I will have time to figure out how to do code-flow analysis any time soon, but maybe someone else will. BTW, did you try using bracket syntax and/or string constants? var json:Object = JSON.parse("{\"abcdefg\":1212121}"); alert(json['abcdefg']); Or const ABCDEFG:String = "abcdefg"; var json:Object = JSON.parse("{\"abcdefg\":1212121}"); alert(json[ABCDEFG]); The latter will help you catch misspellings of the property name. -Alex
Re: flexjs eat json tilesets
the flexjs just 0.6 beta. if the 0.7 have this function is good. it is just give my idea. thanks your hard work -- View this message in context: http://apache-flex-development.247.n4.nabble.com/flexjs-eat-json-tilesets-tp51581p51695.html Sent from the Apache Flex Development mailing list archive at Nabble.com.
Re: flexjs eat json tilesets
On 2/23/16, 9:18 PM, "lizhi" wrote: >thanks. >but i think the flexjs can get the name ,not from the json(server), >from the as code Well, sure, we could do some code-flow analysis. But I don't know how to do that and it wouldn't be a priority of mine at this time because I haven't seen very many code examples where the JSON is a literal within the application. Most of Flex is client-server, IMO. But we'll see what others think. And you are welcome to offer up a patch that does it. Thanks, -Alex
Re: flexjs eat json tilesets
also,change the code to alert(json["abcdefg"]); -- View this message in context: http://apache-flex-development.247.n4.nabble.com/flexjs-eat-json-tilesets-tp51581p51693.html Sent from the Apache Flex Development mailing list archive at Nabble.com.
Re: flexjs eat json tilesets
thanks. but i think the flexjs can get the name ,not from the json(server), from the as code var json:Object = JSON.parse("{\"abcdefg\":1212121}"); alert(json.abcdefg); the "alert(json.abcdefg);" code can get the "abcdefg" as var. -- View this message in context: http://apache-flex-development.247.n4.nabble.com/flexjs-eat-json-tilesets-tp51581p51692.html Sent from the Apache Flex Development mailing list archive at Nabble.com.
Re: flexjs eat json tilesets
The @expose/@export needs to be added before the final compiler optimization pass. Often the JSON is not explicitly included in the source code since it often comes from a server request, so there is no way to examine the source and know which properties to protect from renaming. But you could certainly write a utility that examines a JSON structure and generates a class definition for it. You don't always want to protect the names of variables in an Object. -Alex On 2/23/16, 9:03 PM, "lizhi" wrote: >thanks.but this hard use. >is it the flexjs know the Object type? >if is the Object type. >add /** @expose */ to all var name? > > > >-- >View this message in context: >http://apache-flex-development.247.n4.nabble.com/flexjs-eat-json-tiles >ets-tp51581p51690.html >Sent from the Apache Flex Development mailing list archive at Nabble.com.
Re: flexjs eat json tilesets
thanks.but this hard use. is it the flexjs know the Object type? if is the Object type. add /** @expose */ to all var name? -- View this message in context: http://apache-flex-development.247.n4.nabble.com/flexjs-eat-json-tilesets-tp51581p51690.html Sent from the Apache Flex Development mailing list archive at Nabble.com.
Re: flexjs eat json tilesets
Some property names have already been "exported" by other classes which means they won't be renamed. There might already be a class with a "children" property, for example. -Alex On 2/23/16, 7:25 PM, "lizhi" wrote: >https://github.com/matrix3d/spriteflexjs/blob/master/test/src/com/hsharma/ >hungryHero/TextureAtlas.as > >but why this json class work good. > > > > > >-- >View this message in context: >http://apache-flex-development.247.n4.nabble.com/flexjs-eat-json-tiles >ets-tp51581p51688.html >Sent from the Apache Flex Development mailing list archive at Nabble.com.
Re: flexjs eat json tilesets
https://github.com/matrix3d/spriteflexjs/blob/master/test/src/com/hsharma/hungryHero/TextureAtlas.as but why this json class work good. -- View this message in context: http://apache-flex-development.247.n4.nabble.com/flexjs-eat-json-tilesets-tp51581p51688.html Sent from the Apache Flex Development mailing list archive at Nabble.com.
Re: flexjs eat json tilesets
On 2/23/16, 1:07 AM, "lizhi" wrote: >thanks . >but,if the app have a lot a lot of json.i must code all the class? Well, no, but having class definitions for your data is one of the benefits of Flex/FlexJS and should save you time by making fewer mistakes over time. It might be interesting to see if you can build a utility program that generates the class definitions from JSON output. But you can also not use ADVANCED_OPTIMIZATIONS or use other tricks to deal with renaming like in this post [1]. And there might be a way to cheat where you create a class definition with every property name but not the exact structure of your data and use that for some dummy variable in the app. HTH, -Alex [1] http://stackoverflow.com/questions/7823811/prevent-google-closure-compiler- from-renaming-settings-objects
Re: flexjs eat json tilesets
thanks . but,if the app have a lot a lot of json.i must code all the class? -- View this message in context: http://apache-flex-development.247.n4.nabble.com/flexjs-eat-json-tilesets-tp51581p51671.html Sent from the Apache Flex Development mailing list archive at Nabble.com.
Re: flexjs eat json tilesets
On 2/17/16, 10:46 PM, "omup...@gmail.com on behalf of OmPrakash Muppirala" wrote: >On Feb 17, 2016 10:38 PM, "Alex Harui" wrote: >> >> Hi Lizhi, >> >> Your email did not format well, but IMO, you are seeing expected >>behavior >> in the Google Closure Compiler optimization. Unless you specify >> otherwise, the GCC will rename variables, properties, etc. Using >>straight >> up JSON can be tricky in such situations. You may have to specify and >> even use a class definition for the JSON data structure. > >This is interesting. Is there an example of this kind of pattern >somewhere in the FlexJS examples? I think in FlexJSStore. The JSON data is supposed to be an array of Product instances. The inclusion of Product.as keeps its public properties from being renamed. Really, the uber-thought for FlexJS in general (with Advanced Optimizations) is to not use un-typed references. I still have on my to-do list a compiler option that spits out a warning whenever something resolves to one of a list of "untyped" types (Object, EventDispatcher, IEventDispatcher). I've been told that it is astounding how often we lose the higher-level type via our APIs. If you use event.target or event.relatedObject, you've lost the higher-level type. -Alex
Re: flexjs eat json tilesets
https://github.com/matrix3d/spriteflexjs/blob/master/test/src/com/hsharma/hungryHero/TextureAtlas.as this json class work good. but this work bad. https://github.com/matrix3d/spriteflexjs/blob/master/test/src/TestTMX.as what diff? -- View this message in context: http://apache-flex-development.247.n4.nabble.com/flexjs-eat-json-tilesets-tp51581p51599.html Sent from the Apache Flex Development mailing list archive at Nabble.com.
Re: flexjs eat json tilesets
On Feb 17, 2016 10:38 PM, "Alex Harui" wrote: > > Hi Lizhi, > > Your email did not format well, but IMO, you are seeing expected behavior > in the Google Closure Compiler optimization. Unless you specify > otherwise, the GCC will rename variables, properties, etc. Using straight > up JSON can be tricky in such situations. You may have to specify and > even use a class definition for the JSON data structure. This is interesting. Is there an example of this kind of pattern somewhere in the FlexJS examples? Thanks, Om > > -Alex > > On 2/16/16, 6:59 PM, "lizhi" wrote: > > >package { import flash.display.Bitmap;import flash.display.Loader;import > >flash.display.LoaderInfo; import flash.display.Sprite;import > >flash.display.StageAlign; import flash.display.StageScaleMode; import > >flash.events.Event;import flash.geom.Matrix; import flash.net.URLLoader; > >import flash.net.URLRequest; import flash.text.TextField;import > >spriteflexjs.Stats;/** * ... * @author lizhi */ public class TestTMX > >extends Sprite { private var tmxloader:URLLoader; private var > >pngs:Array = > >[];private var tmxobj:Object; public function TestTMX() > > { tmxloader = > >new URLLoader(new URLRequest("../../assets/tmx/sewers.json")); > >tmxloader.addEventListener(Event.COMPLETE, tmxloader_complete); > >stage.align = StageAlign.TOP_LEFT; stage.scaleMode = > >StageScaleMode.NO_SCALE; addChild(new Stats); } private function > >tmxloader_complete(e:Event):void { tmxobj = JSON.parse(tmxloader.data > >+ > >""); loadNextTile(); } private function loadNextTile():void{ if > >(pngs.length >Loader; > >loader.contentLoaderInfo.addEventListener(Event.COMPLETE, > >loader_complete); > >var tset:Object = tmxobj.tilesets[pngs.length]; var url:String = > >tset.image;url = url.slice(url.lastIndexOf("\/")+1); > >loader.load(new URLRequest("../../assets/tmx/"+url)); }else > >{ > >init();} } private function loader_complete(e:Event):void { > >pngs.push(((e.currentTarget as LoaderInfo).content as > >Bitmap).bitmapData); > >loadNextTile();} private function init():void{ var tw:Number = > >tmxobj.tilewidth; var th:Number = tmxobj.tileheight; for each(var > >layer:Object in tmxobj.layers) { for (var i:int = 0; i < > >layer.data.length; i++ ) { var id:int = > >layer.data[i]; if(id>0){ > >var tset:Object = tmxobj.tilesets[0]; var fg:int = > >tset.firstgid; > >var x:int = int(i % layer.width); var y:int = int(i / > >layer.width); > >var ttw:int = tset.tilewidth; var tth:int = tset.tileheight; var > >numCols:int = tset.imagewidth/ttw; var tx:int = int((id-fg) % > >numCols); > >var ty:int = int((id - fg) / numCols); > >graphics.beginBitmapFill(pngs[0],new > >Matrix(1,0,0,1,x*tw-tx*ttw,y*th-ty*tth)); graphics.drawRect(x * tw, > >y * > >th, tw, th); } } } } }} > >and i can not find "tilesets" in the js-release/ > > > > > > > >-- > >View this message in context: > > http://apache-flex-development.247.n4.nabble.com/flexjs-eat-json-tiles > >ets-tp51581.html > >Sent from the Apache Flex Development mailing list archive at Nabble.com. >
Re: flexjs eat json tilesets
Hi Lizhi, Your email did not format well, but IMO, you are seeing expected behavior in the Google Closure Compiler optimization. Unless you specify otherwise, the GCC will rename variables, properties, etc. Using straight up JSON can be tricky in such situations. You may have to specify and even use a class definition for the JSON data structure. -Alex On 2/16/16, 6:59 PM, "lizhi" wrote: >package { import flash.display.Bitmap;import flash.display.Loader; >import >flash.display.LoaderInfo; import flash.display.Sprite;import >flash.display.StageAlign; import flash.display.StageScaleMode;import >flash.events.Event;import flash.geom.Matrix; import >flash.net.URLLoader; >import flash.net.URLRequest; import flash.text.TextField;import >spriteflexjs.Stats;/** * ... * @author lizhi */ public >class TestTMX >extends Sprite { private var tmxloader:URLLoader; >private var >pngs:Array = >[];private var tmxobj:Object; public function >TestTMX() > { tmxloader = >new URLLoader(new URLRequest("../../assets/tmx/sewers.json")); >tmxloader.addEventListener(Event.COMPLETE, tmxloader_complete); >stage.align = StageAlign.TOP_LEFT; stage.scaleMode = >StageScaleMode.NO_SCALE; addChild(new Stats); >} private function >tmxloader_complete(e:Event):void { tmxobj >= JSON.parse(tmxloader.data >+ >""); loadNextTile(); } >private function loadNextTile():void{ if >(pngs.lengthloader:Loader = new >Loader; >loader.contentLoaderInfo.addEventListener(Event.COMPLETE, >loader_complete); >var tset:Object = tmxobj.tilesets[pngs.length]; >var url:String = >tset.image;url = >url.slice(url.lastIndexOf("\/")+1); >loader.load(new URLRequest("../../assets/tmx/"+url)); >}else >{ >init();} } >private function loader_complete(e:Event):void { >pngs.push(((e.currentTarget as LoaderInfo).content as >Bitmap).bitmapData); >loadNextTile();} private >function init():void{ var tw:Number = >tmxobj.tilewidth; var th:Number = tmxobj.tileheight; >for each(var >layer:Object in tmxobj.layers) { for (var i:int >= 0; i < >layer.data.length; i++ ) { var id:int = >layer.data[i]; if(id>0){ > >var tset:Object = tmxobj.tilesets[0]; >var fg:int = >tset.firstgid; >var x:int = int(i % layer.width); >var y:int = int(i / >layer.width); >var ttw:int = tset.tilewidth; var >tth:int = tset.tileheight; var >numCols:int = tset.imagewidth/ttw; >var tx:int = int((id-fg) % >numCols); >var ty:int = int((id - fg) / numCols); >graphics.beginBitmapFill(pngs[0],new >Matrix(1,0,0,1,x*tw-tx*ttw,y*th-ty*tth)); >graphics.drawRect(x * tw, >y * >th, tw, th); } >} } } }} >and i can not find "tilesets" in the js-release/ > > > >-- >View this message in context: >http://apache-flex-development.247.n4.nabble.com/flexjs-eat-json-tiles >ets-tp51581.html >Sent from the Apache Flex Development mailing list archive at Nabble.com.
flexjs eat json tilesets
package { import flash.display.Bitmap;import flash.display.Loader; import flash.display.LoaderInfo; import flash.display.Sprite;import flash.display.StageAlign; import flash.display.StageScaleMode;import flash.events.Event; import flash.geom.Matrix; import flash.net.URLLoader; import flash.net.URLRequest;import flash.text.TextField;import spriteflexjs.Stats; /** * ... * @author lizhi */ public class TestTMX extends Sprite { private var tmxloader:URLLoader; private var pngs:Array = []; private var tmxobj:Object; public function TestTMX() { tmxloader = new URLLoader(new URLRequest("../../assets/tmx/sewers.json")); tmxloader.addEventListener(Event.COMPLETE, tmxloader_complete); stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE;addChild(new Stats); } private function tmxloader_complete(e:Event):void{ tmxobj = JSON.parse(tmxloader.data + "");loadNextTile(); } private function loadNextTile():void{ if (pngs.length0){ var tset:Object = tmxobj.tilesets[0]; var fg:int = tset.firstgid; var x:int = int(i % layer.width); var y:int = int(i / layer.width); var ttw:int = tset.tilewidth; var tth:int = tset.tileheight; var numCols:int = tset.imagewidth/ttw; var tx:int = int((id-fg) % numCols); var ty:int = int((id - fg) / numCols); graphics.beginBitmapFill(pngs[0],new Matrix(1,0,0,1,x*tw-tx*ttw,y*th-ty*tth)); graphics.drawRect(x * tw, y * th, tw, th);} } } } }} and i can not find "tilesets" in the js-release/ -- View this message in context: http://apache-flex-development.2333347.n4.nabble.com/flexjs-eat-json-tilesets-tp51581.html Sent from the Apache Flex Development mailing list archive at Nabble.com.