a question about flex preloaders - apache-flex

I'm moving to a pure as3 environment into flex and I have a question about preloaders.
For one of my apps in particular when the swf loaded I would add a screen with an animated preloader. Then at a particular point in my code when I know all of my xml has been parsed, UI built and all initiliztion done I dispatch a "done" event which removes the preloader.
How can I achieve this is flex? I've only ever really seen flex preloaders that are percentage based which I believe represent the actual loading of the swf itself?

Please read the flex cookbook for preloaders, they have some demo applications, that could help u out
actually there is a preloader property in the application tag,
that could be wht u might help u out
tc
Ankur Sharma

Flex has a ProgressBar control that you can use for similar purposes. If you want to continue to use your own custom animated progress bar, you can add that Sprite to the rawChildren of a Container (preferably Canvas) and show it as a modal pop-up using the PopUpManager - remove the pop-up from the done event's handler.
The overriden addChild method of the Container class will throw an error if you pass a child that doesn't extend UIComponent - that's why you should use rawChildren.addChild.

Yep default flex preloader represents the loading of the swf itself.
If I were you, I would use the Task library from the Cairngorm 3 Libs, works perfectly with a preloader :
http://opensource.adobe.com/svn/opensource/cairngorm3/trunk/libraries/TaskTest/src/samples/TaskFlowPreloader.as

Related

Flex 3 - How to make a circular progress bar?

I am a beginner in Flex. For my appln, I wanted to have the progress bar, but not the default that Flex Framework provides.
I wanted to have a circular loading "progressbar" that would move in circular fashion before completing one complete revolution to 100%.
Can I do that in Flex 3 ? If yes, how ?
Thanks in advance.
Creating your own custom preloader is easy enough. You just need to set the new preloader class in the 'preloader' property of the Application tag.
From there, your class (which should extend ProgressBar) can use simple Actiosncript to animation/draw or you can use a swf animation (done with Flash CS). There are several good examples of this on google.
Something like this? http://activeden.net/item/as3-circle-preloader-circular-progress-bar/88763
Use preloader or extend the progress bar component in Flex
You can have a circle component and a hidden progress bar in it. And for each progress bar event, you can paint a block on the circle.
there is a property in Application "preloader". try setting your own SWC file to this property.
You should use an already created component.
Here is a circular progress bar component created using Degrafa.
http://axelscript.com/wp-content/Examples/CircularProgress/CircularProgress.html
You can see the code at
http://axelscript.com/wp-content/Examples/CircularProgress/srcview/index.html
The code is pretty simple , and as the component is shipped as a mxml component, integration should be very simple.
All you need is the degrafa.swc to be in the lib folder of your project for this to work.
You could use AS3GIF and create your own "circular progress" animated GIF.
If, for example, your animated GIF has 20 frames, you can call the function GIFPlayer.gotoAndStop(pFrame: int) at each 5% step.

Best way to do loaders in a flex application?

What is the best way to do a loader in a flex application? I have an animated .gif that is to be used as our loader (whenever I need to wait for an action to complete), and I am not sure the best way to do it.
This is how I am thinking:
Have the loader be a custom component.
On the parent application, add an event listener for my custom event AceEvent.SHOW_LOADER.
In the event listener, use the PopUpManager to show the loader.
Listen for AceEvent.HIDE_LOADER.
Get rid fo the loader via PopUpManager.
What do you think about this? Is there a better way to do it?
Thanks!
Andrew
Well, last I checked, animated gifs don't work in Flex unless you have a workaround. Still, I wouldn't use an animated gif to create an animation because of their low quality. I would just recreate it using Flash.
The way I would do the loader however would be very different. personally, I don't believe in 'system loaders' unless it's your application's preloader. The reason for this is that there could be more than one thing loading at the same time (which might not know about each other) which means that the loader popup could disappear before everything is loaded (first one loads, dispatches event and removes popup, while the other is still loading).
What I like to do is create a custom component for the popup loader (since it will be reused quite a bit) and from there I can either use states the are appropriate for my view or have a boolean flag binded to show the popup when true (this can easily be done using frameworks like Parsley). The popup would only cover the part of the system that's actually loading data (since I doubt that your whole app is loading data at the same time) which makes for a better UX.
I ended up using as3gif (until I can get this recreated as a .swf). The way I do this is by using my custom event class (AceEvent.SHOW_LOADER and AceEvent.HIDE_LOADER), which bubbles up to the top. I then use the PopUpManager to add/remove this with modal to disable the application.

Make a Spark TitleWindow modal without using much AS3?

I want to be able to show a Spark TitleWindow container as a modal without having to construct it by code via AS3. I tried creating the TitleWindow before-hand manually by dragging and resizing it around and adding objects, etc then hiding it. Then on a button, I set the called function to the ones below:
public function doPopup():void {
testWindow.visible = true;
PopUpManager.addPopUp(testWindow, this, true);
}
Unfortunately, this only shows testWindow but not as a modal. I want it to be like this so that I can freely resize and design the layout of my TitleWindow and only have to call some function to show it as a modal one.
I'm pretty sure the reason you are seeing this behavior is because your TitleWindow (that you've declared within the mxml of the parent container) is already added to the stage even though it is set as not visible. A workaround you could try is to call this.removeElement(testWindow) in a creation complete handler for the parent container. That will get it off the stage so the PopUpManager can add it later properly.
Having said that, I would recommend putting your TitleWindow into a separate mxml file and instantiate it using the PopUpManager. It's cleaner that way and you can still use the design mode to lay it out as you see fit.
Hope that helps.
Try the Cairngorm 3 Popup library :
http://opensource.adobe.com/wiki/display/cairngorm/HowToUseCairngormPopup

What kind of Flex component can I utilize in NativeWindow?

I'm developing Adobe Air application.
To show additional window, I create NativeWindow object.
In the object, "stage.addChild( Sprite Obj )" does work, but almost all other flex components do not work.
Actually I want to add 'spark.components.BorderContainer', 'spark.components.Group', 'mx.controls.Image', etc., but cannot.
One solution I found is to use 'flash.html.HTMLLoader' and to display rich content (that includes images and styled text) into the window.
Is there any better way to show rich content?
NativeWindow is not a Flex container.
Use spark.components.Window or mx.core.Window - they allow BorderContainer, Group and Image to be added (do not forget to use window.addElement() method).

How to get the width and height in ActionScript for a Flex application running inside the flash player in the web browser

Does anyone know how to get the width and height in ActionScript for a Flex application running inside the flash player in the web browser.
e.g. In the web browser I can use the tag to embed a Flex application (as a .swf). To the embed tag, I can provide the dimensions. I would like to get these dimensions inside the flex application action script.
Thanks in advance,
Regards
Vivek
As of Flex 4.0, Adobe recommends using FlexGlobals.topLevelApplication instead of Application.application.
Depending upon what you are doing, you can look into using stage. But, if you do, be aware that the stage will grow to contain movie clips that go outside of the bounds of the application. So the stage is frequently larger than the actual application.
I Flex you can access Application.application.height and Application.application.width.
You can use stage.stageWidth/stage.stageHeight. Be sur to call that from a DisplayObject that is on the display list or else stage is going to be null. It works for both Flex and Actionscript projects.

Resources