How to have a loading bar for ModestMap?
I want have a loading bar for the ModestMap, i tried to write code like this:
var txt:TextField = new TextField();
txt.x = 100;
txt.y = 100;
addChild(txt);
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS,loadingHandler);
function loadingHandler(event:ProgressEvent):void {
var loadInfo:uint = (event.bytesLoaded / event.bytesTotal)*100;
txt.text = String("loading:" + loadInfo + "%");
}
but it does not work, until the load finished, the txt cant be visible, i dont know why.
if i want this bar in flash cs3, how should i do ?
waiting your help, thanks!
var txt:TextField = new TextField();
txt.x = 100;
txt.y = 100;
addChild(txt);
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS,loadingHandler);
function loadingHandler(event:ProgressEvent):void {
var loadInfo:uint = (event.bytesLoaded / event.bytesTotal)*100;
txt.text = String("loading:" + loadInfo + "%");
}
but it does not work, until the load finished, the txt cant be visible, i dont know why.
if i want this bar in flash cs3, how should i do ?
waiting your help, thanks!
5
people have this question
I have this question, too!
Tell me when someone answers.
The more people who ask this question, the more it gets noticed.
The more people who ask this question, the more it gets noticed.
Create a customer community for your own organization
Plans starting at $19/month
-
Inappropriate?Do you mean that you want a progress bar for the tiles as they are loaded? Try the following:
var bar:ProgressBar = new mx.controls.ProgressBar();
bar.source = map.grid;
somePanel.addChild(bar);
I had to override the TileGrid's onProgress function to get it to function the way that I wanted. -
What modification did you make? Was something wrong, or was it just to get it working with the Flex ProgessBar? -
It may be a bug or it may have been intentional. The onProgress function seemed to output previousOpenRequests - openRequests out of previousOpenRequests. However, previousOpenRequests gets modified somewhere else during the course of loading tiles, which makes it inaccurate for sending to the progress bar.
Instead, I did the following to calculate the number of images loaded out of the total (this is from memory so the method names may not be quite right):
protected var calcNumTiles:Boolean = true;
protected var numImages:int = 0;
private function onBeginTileLoading():void {
calcNumImages = true;
// rest of method the same
}
private function onProgress():void {
var count:int = 0;
for (var name:String in layersNeeded) {
if (layersNeeded[name]) {
count += layersNeeded[name].length;
}
}
if (calcNumImages) {
numImages = count;
calcNumImages = false;
}
dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS, false, false, numImages - count, numImages));
} -
Right! Good stuff. Thanks for the speedy response. We're digging around TileGrid quite a bit in the new Google Code repository. It's not currently getting any cleaner, but it really should soon. Watch this space! -
I'll be looking forward to a cleaner TileGrid. It's rather imposing in its current form. I'm running a custom version of it (for the progress event and to give access to visibleTiles and something else that I can't recall). As you are cleaning it up, consider using URLLoader in a binary data form to cache PNG/GIF bytearrays, then using Loader.loadBytes. This should save a good chunk of memory over caching Loaders. I had a version of TileGrid that did this at one point, but ended up scrapping it because while Loader.loadBytes() is great for just showing a tile, it isn't fast enough to animate them.
Loading Profile...



