Showing posts with label AIR. Show all posts
Showing posts with label AIR. Show all posts
2009-04-08
Problem drawing big bitmapdata in FP 10
Today I was having problem drawing big bitmapdatas, and save them to disk in Air. When I was trying to save an image with size 2933*5447 the image came out cropped. After some googleing I found that the limit of 8191px in Flashplayer 10 only represents the limit of an displayObjects max size on the stage. The actual max size of a BitmapData seams to be 4096px, so the application ignores to throw error, it just cropps the BitmapData. The solution for this problem can be found here http://blog.formatlos.de/2008/12/11/bitmapdatadraw-is-limited-to-4096px/.
2008-09-01
Problem removing blankspaces with split(" ").join("");
Yesterday I was playing around with Adobe Air and flex. My goal was to parse a productprice from an HTML-site by splitting the pricetag in to ”kronor” and ”oren” (pounds and cents) My only problem was that ”kronor” below 10 just contained one number, before that number was a blankspace to balance the textalign on the site.
So I built a function that was suppose to remove the blankspaces with split(” ”).join(””); , but no success. After some testing I tryed the string.charCodeAt(index:Number = 0);. This function returns a “charCode” , the numeric Unicode character code of the character ,at a specified index, this gave the result 160. After some googleing on unicode 160 I found this site http://bytes.com/forum/post1462660-5.html. This sort of blankspace-characters are called a ”non breaking space” http://en.wikipedia.org/wiki/Non-breaking_space. I also found that there are some more types of whitespace - characters that may be used by unicode but not removed by the split(” ”).join(””) – function. So to solve this problem I some how had to force the special character in to the splitjoin-function. After some reading about strings on ”livedocs” ,http://livedocs.adobe.com/flex/3/langref/String.html ,I found the String.fromCharCode(), that simply translates a list of commaseparated Unicodenumbers to a string. So instead of using split(“ “).join(“”) to remove the non breaking space I used split(String.fromCharCode(160)).join("").
So I built a function that was suppose to remove the blankspaces with split(” ”).join(””); , but no success. After some testing I tryed the string.charCodeAt(index:Number = 0);. This function returns a “charCode” , the numeric Unicode character code of the character ,at a specified index, this gave the result 160. After some googleing on unicode 160 I found this site http://bytes.com/forum/post1462660-5.html. This sort of blankspace-characters are called a ”non breaking space” http://en.wikipedia.org/wiki/Non-breaking_space. I also found that there are some more types of whitespace - characters that may be used by unicode but not removed by the split(” ”).join(””) – function. So to solve this problem I some how had to force the special character in to the splitjoin-function. After some reading about strings on ”livedocs” ,http://livedocs.adobe.com/flex/3/langref/String.html ,I found the String.fromCharCode(), that simply translates a list of commaseparated Unicodenumbers to a string. So instead of using split(“ “).join(“”) to remove the non breaking space I used split(String.fromCharCode(160)).join("").
2008-08-31
Papervision 3D Framerate
Let us share some constructive hands-on tips or trix on how to increase framerates. There's a lot of design issues from modeling 3D-objects to bind them to value-/business objects (classes). However, you should also take the rendering principals of the Flashplayer and your 3D-API in consideration! The gems in this topics may be, in no particular order, under clever headlines, so feel free to contribute by comments.
1) Override Flex default framerate of 24 by setting the desired framerate Application property in *.mxml (haven't got it to work from CSS). Try framerate 60, and hope that the Flashplayer may reach the fps of 40 once in a while.
2) Ask your self when and why you need to run onEnterFrame()! Even for a design built with constant movement in mind, it is a good strategy to provide for situations where a 3D world is allowed to freeze for a couple of seconds. If you can make it freeze without the user notice it - good for you. You will need that time to load additional assets or resources.
IMPORTANT!!! Try NOT to use onEnterFrame() at all in your 3D viewport rendering engine! Try the Timer intervall instead. And above all - try NOT to use two or more onEnterFrame()-callbacks in parallell, that will probably sink you application framerate below 10 fps.
In PV3D all DisplayObject3D have a pointer to the scene or context they belong to. Therefor you may choose to use the Scene object as the eventdispatcher for such events as PLAY and STOP to control when to stop or run the onEnterFrame.
3) If you know, or if the 3D object or face itself know that it should be invisible - set its visibility to false. In that way the the culling process does not even need to calculate.
4) Z-depth and culling calculus are process intensive. One finding I had was with a cube, or rather six individual planes, with no awareness of eachother, in a group forming a cubelike shape. I wanted to keep the cube in constant movement of a Perlin noiced sine function in each degree of freedom (DOF). The cube was rotated with in a slow wobbeling motion showing the same three faces to the camera, two sides and the rooftop. I found that the framerate decreased when one face - the rooftop - had it's normal almost perpendicular to the camera. The more the rooftop pointed it's normal direction towards the camera the framerate increased.
Thus, a large surface with a tiny projection to the view plane is more computationally heavy than when the same side projects more of its surface to the view plane! By rotating the default angle of my cube slightly, the culling did not kick in, and I increased the framerate by two times.
5) Over all for FlashPlayer rendering, check how Bitmap Cache Policy can be used in your project..
1) Override Flex default framerate of 24 by setting the desired framerate Application property in *.mxml (haven't got it to work from CSS). Try framerate 60, and hope that the Flashplayer may reach the fps of 40 once in a while.
2) Ask your self when and why you need to run onEnterFrame()! Even for a design built with constant movement in mind, it is a good strategy to provide for situations where a 3D world is allowed to freeze for a couple of seconds. If you can make it freeze without the user notice it - good for you. You will need that time to load additional assets or resources.
IMPORTANT!!! Try NOT to use onEnterFrame() at all in your 3D viewport rendering engine! Try the Timer intervall instead. And above all - try NOT to use two or more onEnterFrame()-callbacks in parallell, that will probably sink you application framerate below 10 fps.
In PV3D all DisplayObject3D have a pointer to the scene or context they belong to. Therefor you may choose to use the Scene object as the eventdispatcher for such events as PLAY and STOP to control when to stop or run the onEnterFrame.
3) If you know, or if the 3D object or face itself know that it should be invisible - set its visibility to false. In that way the the culling process does not even need to calculate.
4) Z-depth and culling calculus are process intensive. One finding I had was with a cube, or rather six individual planes, with no awareness of eachother, in a group forming a cubelike shape. I wanted to keep the cube in constant movement of a Perlin noiced sine function in each degree of freedom (DOF). The cube was rotated with in a slow wobbeling motion showing the same three faces to the camera, two sides and the rooftop. I found that the framerate decreased when one face - the rooftop - had it's normal almost perpendicular to the camera. The more the rooftop pointed it's normal direction towards the camera the framerate increased.
Thus, a large surface with a tiny projection to the view plane is more computationally heavy than when the same side projects more of its surface to the view plane! By rotating the default angle of my cube slightly, the culling did not kick in, and I increased the framerate by two times.
5) Over all for FlashPlayer rendering, check how Bitmap Cache Policy can be used in your project..
2008-08-28
AIR and the pitfalls of the Security Sandbox (and eternal damnation of Singletons)
For a few days now I've been working on an AIR application to generate XML for a product called Sound Manager. Sound Manager, which we built for a client of ours - DinahMoe, is a pretty nifty system which allows them to hand over a couple of as-files to their clients through which the end client's developers can dispatch events describing what's going on in the Flash app. DinahMoe can then orchestrate sounds for the app by linking the events to actions playing, stopping, pausing, transforming, jumping and so forth, in sounds.
In order to lower the complexity for the end client, we put all the code that actually does anything into the sound libraries that are compiled by the guys at DinahMoe (or is it just guy, Johan?). The objects in the sound libraries then listen for the Sound Managers events and do what has to be done... and what has to be done is off course described in XML.
So the AIR admin lets DinahMoe build the XML through a rich interface where actions can be categorized in folders, copied, edited and so on. Then it was time for the testing. In short, I wanted the AIR app to instanciate the SoundManager, tell it to load the XML and the sound libs and then fire the events I wanted to test. Here's where everything goes pear shaped. The AIR app lives in the Application Sandbox, the loaded swf:s liv in the Loca file Sandbox. So they each instanciate their own singletons and all communication is lost.
So I built a swf which instanciates the SoundManager, and let the AIR app load the SWF... but as it was placed inside the apps application directory, it was too run in the Application Sandbox. So I copied it to the same directory as the Sound libraries that were to be loaded... and now they all ended up in the same Sandbox... but still they could not communicate. And here's where I lost hope. So now I return handles through the SoundLibraries and call each and everyone of them with each event. Not pretty but It's the best I could com up with.
So what is the deal? Are SWF:s in the Local File Sandbox prohibited from talking to each other? Is there a solution? Anyone?
In order to lower the complexity for the end client, we put all the code that actually does anything into the sound libraries that are compiled by the guys at DinahMoe (or is it just guy, Johan?). The objects in the sound libraries then listen for the Sound Managers events and do what has to be done... and what has to be done is off course described in XML.
So the AIR admin lets DinahMoe build the XML through a rich interface where actions can be categorized in folders, copied, edited and so on. Then it was time for the testing. In short, I wanted the AIR app to instanciate the SoundManager, tell it to load the XML and the sound libs and then fire the events I wanted to test. Here's where everything goes pear shaped. The AIR app lives in the Application Sandbox, the loaded swf:s liv in the Loca file Sandbox. So they each instanciate their own singletons and all communication is lost.
So I built a swf which instanciates the SoundManager, and let the AIR app load the SWF... but as it was placed inside the apps application directory, it was too run in the Application Sandbox. So I copied it to the same directory as the Sound libraries that were to be loaded... and now they all ended up in the same Sandbox... but still they could not communicate. And here's where I lost hope. So now I return handles through the SoundLibraries and call each and everyone of them with each event. Not pretty but It's the best I could com up with.
So what is the deal? Are SWF:s in the Local File Sandbox prohibited from talking to each other? Is there a solution? Anyone?
All Your Base Are Belong To Flex, Flash, AIR, .NET and such
Here we go. This is the official All Your Base blog for sharing our wisdom and experience in developing RIA:s with Flash, Flex, AIR, .NET and all other things cool and nerdy.
Subscribe to:
Posts (Atom)