it is not so easy as you think!
to set it 60 call:
Object(FlexGlobals.topLevelApplication).stage.frameRate=60;
or... create this setter
public static function set frameRate(framerate:int):void{
Object(FlexGlobals.topLevelApplication).stage.frameRate=framerate;
}
and call
frameRate=60;
you may also define it in mxml
frameRate="60"
The default value of the player is 25; increasing the frame rates you consume more cpu! don't forget that you application will run in a slower computer than yours!
Flexache, is the pain you feel in your brain when you coding on Adobe’s Flex Builder, Flash builder with Flex SDK and Actionscript in general. The pain is starting from the eyes, as you can’t believe what you see and is getting deep in your head as you can’t fix. In this blog I‘ll give you painkiller to get out of a lot strange troubles showing solutions and techniques in Flex.
Showing posts with label flex. Show all posts
Showing posts with label flex. Show all posts
Wednesday, 29 June 2011
Sunday, 12 June 2011
Flex4, how to wait object to be completely initialized; how to give time to objects to be completely initialized
Suppose that you have an Object called Circus. This object is too complex (like a real circus). The follow init() function creates the circus it but in real programming world the Circus object is not prepared because the Circus must be render its components, update several graphics objects .
internal function init():void{
//create my.. circus…
myCircus=new Circus(“My X-circus");
//initialize
myCircus.x=10; myCircus.y=40;
//play
myCircus.play();
myCircus.cashier.addMoney(100.50); //this might be wrong, as the circus in not ready yet!
}
This problem occurred on simpler objects also… like the Flex’s Label. If on “applicationComplete” you apply a value to “text” property of a Label a text (i.e. “hellow world”) and right after you try to get the “width” of the Label object, you might be get WRONG value, a not real width; this because the Label object is not yet prepared.
Well, how to get that an object is completed? With Flex’s Label, the event you must Listen is the “FlexEvent.UPDATE_COMPLETE” and not other “UPDATE_COMPLETE” because Flex offers and other from other Eventxxx classes. Note that this is working in Flex 4.0.
So… the Circus object must supports and dispatch once upon a time the “FlexEvent.UPDATE_COMPLETE” to continue in safe way the calculations with its properties.
But, what happen if the Circus doesn’t supports this event? Unfortunately this is happening in real world with several 3rd party components / object.
Bellow there is a solution that is not so professional but it is the only chance to make it work! ;) What I do here is that I am working for a while with Event.ENTER_FRAME, with this way I give some time to then whole application and its running objects to complete uncompleted calculations.
//this is my own counter to count the passed time.
internal var myWaitCounter:int;
internal function init():void{
//create my.. circus…
myCircus=new Circus(“My X-circus");
//initialize
myCircus.x=10; myCircus.y=40;
//prepare and activate my listener pf ENTER_FRAME event
myWaitCounter=0;
addEventListener(Event.ENTER_FRAME,Handler_WaitForCompletion);
}
internal function Handler_WaitForCompletion (e:Event):void{
//add to my counter the time
myWaitCounter+=1000/ Object(FlexGlobals.topLevelApplication).stage.frameRate;
//if, 500ms (0,5sec) passed, then call the start() after remove then listener
//in general it is very important to remove the listeners where you don’t need any more
if (myWaitCounter >=500) {
removeEventListener(Event.ENTER_FRAME,Handler_WaitForCompletion);
start();
}
}
protected function start():void{
//now you are ready to play with you circus safely!
myCircus.play();
}
Saturday, 4 June 2011
Flex, Determining which server/domain a SWF is hosted on
situation | |
Here’s a handy tip which can help you when deploying Flex applications on mulitple servers (such as a staging/production server). Basically you can listen for the Application tag to dispatch the applicationComplete event, grab the URL of the SWF using the loaderInfo.url property, and then use the URLUtil.getServerName() method to parse out the server name. | |
problem | |
adobe flex4 flex 4.0 AS3.0 Determining which server/domain a SWF is hosted on | How to get the domain where the swf is hosted ---- > page: dn | |
difficulty level | |
0/10 :))) | |
compatibility | |
flex4, as3 | |
solution | |
In prior version of Flex 4.0 use this: URLUtil.getServerName(Application.application.loaderInfo.url); In 4.0 use this: because Application is no longer available in 4.0 URLUtil.getServerName(FlexGlobals.topLevelApplication.url) | |
Tuesday, 31 May 2011
Flex4, trace function is not working anymore!
situation | |
This is known bug! This problem occurred when you exported a “release” previously; thenceforth the trace() messages are not appeared in the console window. !!! If you are beginner on Flex, read the "attention" at the bottom of this post! !!! | |
problem | |
adobe flex4 AS3.0 Flex4, trace function is not working anymore! ---- > page: dn | |
difficulty level | |
3/10 :)) | |
compatibility | |
flex4, as3 | |
solution | |
Try 1 1. Clean the build: Project -> Clean -> Clean project (select this one specific from the list) -> ok 2. “Debug” the application (pressing the “bug” button); rebuild will be done 3. The problem should be solved! Otherwise try try2. Try 2 1. Restart the Flex / Flash builder IDE 2. Restart the browser with Adobe Flash Debugger Player 3. Clean the build: Project -> Clean -> Clean project (select this one specific from the list) -> ok 4. “Debug” the application (pressing the “bug” button); rebuild will be done 3. The problem should be solved! | |
attention | |
Important note for beginners: You should “debug” the application (pressing the “bug” button) and not “run” the application (pressing the “play” button) to see the trace() messages at the console window. In “run” mode the trace() message are omitted. | |
Tuesday, 24 May 2011
flex4, how to make an image brighter, i.e. for focus purposes, without modify it
| situation | |
| how to make easy(!) modifications in Image components with out modifying their data. The data modification (image modification) requires a lot cpu resources as result low performance. | |
| problem | |
| adobe flex4 AS3.0 how to make an image brighter, i.e. for focus purposes, without modify it > page: dn | |
| difficulty level | |
| 2/10 :) | |
| compatibility | |
| flex4, as3 | |
| solution | |
| - drop a Label on the Image component to cover it, clear text property - on this Label... set as background color the white color - also set as blendmode the "overlay" value - also set as backgroundAlpha the value 0.5 - now... on runtime play with "alpha" property of the Label with values 0..400 | |
Sunday, 8 May 2011
Flex: how to make a image cache? (easier way) - REFdn4007673813
| situation | |
| how to make a image cache? | |
| problem | |
| adobe flex4 AS3.0 the image component how to load images save them to cache… and how apply them to Image components --- > page by dn | |
| difficulty level | |
| 9/10 :( | |
| solution | |
| In order to make a cashe of the photos/images, I do the follow simple way: - With URLLoader I download the data… the "Complete" event gives me the "data" property… in this property the data of the image is in binary format (don't be afraid). I save this "data" to another variable (or array) of Object type. For this example, I named this variable "downloadData" you will see bellow. - In order to load the data on a visual component Image, I do the follow code: myImage.data=downloadData; | |
| attention | |
| no attentions! | |
How to Cache Images in Your Flex Application - REFdn5077575832
Caching images in your Flex application can greatly improve performance and reduce the overhead of loading external resources.
And I’m not simply talking about using the
To get started, you’ll need a hash map to store the image data. A
Loading an image for the first time is the same as usual. You create a new
Once the image has finished loading, you add a copy of the bitmap data to the hash map using the image URL as the hash key:
Now we can use the image as many times as we want without ever having to load it again!
To take advantage of this, you’ll need to check the hash map every time you create a new image (or change the
And that’s it!
If you have an application that loads a large number of images you may want to limit the number of cached images to prevent the Flash player memory usage from getting out of hand, but in general caching even several dozen large images only results in a slightly increased footprint.
And I’m not simply talking about using the
cacheAsBitmap property to improve rendering performance or the cachePolicy property to speed up animations. I’m talking about caching the actual bitmap data of an image.To get started, you’ll need a hash map to store the image data. A
Dictionary or an associative array will also work just fine.Loading an image for the first time is the same as usual. You create a new
Image object and add a listener for the COMPLETE event:| var image : Image = new Image (); image.addEventListener (Event.COMPLETE, onImageComplete); |
Once the image has finished loading, you add a copy of the bitmap data to the hash map using the image URL as the hash key:
| private function onImageComplete (event : Event) : void { var image : Image = event.target as Image; if (! imageCache.containsKey (image.source)) { var bitmapData : BitmapData = new BitmapData (image.content.width, image.content.height, true); bitmapData.draw (image.content); imageCache.put (image.source, bitmapData); } } |
Now we can use the image as many times as we want without ever having to load it again!
To take advantage of this, you’ll need to check the hash map every time you create a new image (or change the
source property) to see if you’ve already cached it:| var image : Image = new Image (); image.addEventListener (Event.COMPLETE, onImageComplete); if (imageCache.containsKey (imageURL)) { image.source = new Bitmap (imageCache.getValue (imageURL)); } else { image.source = imageURL; } |
And that’s it!
If you have an application that loads a large number of images you may want to limit the number of cached images to prevent the Flash player memory usage from getting out of hand, but in general caching even several dozen large images only results in a slightly increased footprint.
Thursday, 28 April 2011
flex, air, How to write a file where the application is located
| problem | |
| adobe flex4 AS3.0, filestraem (air) How to write a file where the application is located | the mystery "fileWriteResource" hidden error | how to write files in applicationDirectory (where is not allowed) [tested in windows only] --- > page by dennis | |
| solution | |
| How to write a file where the application is located in the follow example, the variable "filename" is String and has as value the the file name without path, i.e.: "sample.txt" the follow code doesn't work, produces an error "fileWriteResource" that is not even thrown! var newFile:File=File.applicationDirectory.resolvePath(filename); use the follow code: var newFile:File=File(File.getRootDirectories()[0]).resolvePath(File.applicationDirectory.nativePath+File.separator+filename); //I am not kidding... it is working | |
Subscribe to:
Posts (Atom)