Progress Bar reset in Flex - actionscript-3

I have been working on resetting a progressBar in flex, but the thing is that progressbar correctly displays the bytes loaded while the file is downloaded for the first time, but for other consecutive file downloads, it just stays at 100% although the file is downloaded, How do I reset the the progressbar so that it correctly shows the progress for other files too.
I have tried using pb.setProgress(0,100) before the progressbar starts to set the progress to zero but it also does not helps.
Also I have set the mode to manual.
Ok here is what I have done :
Have a progress Event in which I am setting the progress of the progressBar as :
public function progressHandler(event:ProgressEvent):void
{
pb.width=300;
pb.height=30;
pb.labelPlacement="center";
pb.mode="manual";
pb.setProgress(event.bytesLoaded, event.bytesTotal);
}
Also in the open event I am calling a title window and adding the progress bar into it and then popping it using the popup manager as :
public function openWindow(event:Event):void {
tWin.title = "Please Wait";
tWin.width=400;
tWin.height=100;
tWin.addChild(pb);
PopUpManager.addPopUp(tWin, this, true,PopUpManagerChildList.POPUP);
PopUpManager.bringToFront(tWin);
PopUpManager.centerPopUp(tWin);
}
Then finally in the complete event, i am removing the popupmanager and setting the progress to be zero as :
public function completeHandler(evt:Event):void {
PopUpManager.removePopUp(tWin);
pb.setProgress(0,100);
}
But still the progress bar remains at 100% for any consecutive file downloads.
Any help..??

Related

WinRT, Metro, Win8 remember list position w/o animation

I have a listview which i reload when i click on an item. I want to remember the scroll position so I use the following code:
private double scrollPosition;
public void SaveListPosition()
{
scrollPosition = scrollViewer.VerticalOffset;
}
public void ScrollToSavedPosition()
{
scrollViewer.ChangeView(0, scrollPosition, null, false);
}
Its working fine, but it shows the scrolling. After I change the ChangeView method's disableAnimation parameter to true it doesn't show scrolling as expected, but it completely messes up list positions and doesn't scroll to the element that I clicked.
So questions are:
1) is this a bug in winrt?
2) can I override the ChangeView's animation so it will instantly scroll exactly like supplying true for the disableAnimation parameter?
3) Any other solution?

Java GUI - SwingWorker and gif

Ok so I am doing some taks of parsing data from document in SwingWorker which takes quite good amount of time.
And I am showing "loading gif" as JButton icon while doing this and also updating label every 15% done.
Its working ,but only problem is that gif is moving slowly or sometiems stop for sec and then start again. GIF is basically not animating smooth.
JButton is disabled and I set this gift as icon for disabled JButton.
In MainGUI class:
jButton3.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/images/loading.gif")));
After user click on button I call this:
runLoader=new CashLoader(jButton3, jLabel2, ucty, userLock);
jButton3.setEnabled(false);
jLabel2.setForeground(Color.GRAY);
executor.execute(runLoader);
CashLoader thread do this:
#Override
protected Object doInBackground() {
// long code is here
// somewhere in the code I call evey 15% done this:
publish(new PublishingClass(sum, true));
}
#Override
protected void process(List<PublishingClass> sum){
for (PublishingClass publishingThing : sum) {
if (publishingThing .isOrangeColor()) lblSum.setForeground(new Color(226,182,3));
lblSum.setText(""+publishingThing .getNumber()+" %");
}
}
#Override
protected void done(){
btnReload.setEnabled(true);
...
}
Thats sorter version of code. As you can see I am not doing anything in SwingWorker doInBackground() method with JButton. Once its set to disabled it should show gif as its icon. Which is obviously doing ,but not smooth ,it just stops for few seconds or once I move with mouse over window then it starts moving gif . It basicly shows laggy gif.

Progress Event not Triggering ONLINE

I am making a Flash Photogallery and I have a problem with my preloader. My gallery works fine offline(in simulating download) but the problem is when it's online the loading percentage won't show up. So far I figured out that the ProgressEvent is not triggering when gallery loads full size image. Sometimes it triggers on 100%, sometimes it triggers on time but usually it don't trigger. Here is the link of my gallery and some code: solarratko.netii.net
public function kreni(f:String) //function that start when user click on thumbnail
{
URLrequest=new URLRequest(f); //URLrequest for image in full size
dspLoader.load(URLrequest); //loading the image
preloader.visible = true;//prelaoder that shows up is visible
h.visible=true;//text area for percentage is visible
dspLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progres);//adding progress event
dspLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, kraj);//adding complete event
}
public function progres(e:Event):void
{
var perc:Number = e.target.bytesLoaded / e.target.bytesTotal;//calculatin percentage
h.text = Math.ceil(perc*100).toString();//displaying percentage wich is not working online or it start too late
}
public function kraj(e:Event):void
{
h.text="";
preloader.visible = false;
h.visible=false;
}

Can't get a working progress bar for file download AS3

I'm currently enrolled in an ActionScript course, and cannot seem to get my progress bar to work correctly. We were tasked with creating a simple image loader application, which would access externally hosted images (through use of a PHP proxy script), and then spit the image onto the user's screen (with a progress event and progress bar to track the image's download progress).
However, when I run it, I get these mysterious black graphical glitches everywhere, as well as a non-functioning progress bar. In some browsers I get the following error: "ArgumentError: Error #2109: Frame label NaN not found in scene NaN. at flash.display.MovieClip/gotoAndStop() at Document/imageLoadProgress().
Here is my code - I cant for the life of me figure out what is wrong. I figure it has something to do with the imageLoadProgress() function, or my progress bar (which is just a simple 100-frame movie clip with a motion tween and a "stop()" command at the beginning).
public function loadImage()
{
var imageURL:String = imageArray[currentImageIndex];
if(loaderInfo.url.substr(0,4) == "http")
{
trace("we're online");
//use the proxy script
//escape() will replace spaces in file names with %20
imageURL = "./image_proxy.php?filename=" + escape(imageArray[currentImageIndex]);
}
var imageRequest:URLRequest = new URLRequest(imageURL);
this.imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, this.imageIOError);
this.imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, this.imageLoadProgress);
this.imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.imageLoadComplete);
this.imageLoader.load(imageRequest);
//end loadImage
}
public function imageIOError(e:Event)
{
trace("ImageIOError called. Error=" + e);
//end imageIOError
}
public function imageLoadProgress(e:ProgressEvent)
{
var percentLoaded:Number = e.bytesLoaded/e.bytesTotal;
percentLoaded = Math.round(percentLoaded * 100);
//this.progress_mc.scaleY = percentLoaded;
if (percentLoaded < 1)
{
this.progressBar.gotoAndStop(1);
}
else
{
this.progressBar.gotoAndStop(percentLoaded);
}
//end imageLoadProgress
}
Your loader script seems absolutely fine to me, except for a tiny flaw:
The only way the NaN(== not a Number) in your error message makes sense to me is if your ProgressEvent's bytesTotal property equals 0 - because division by zero doesn't produce valid results, as we all know.
I can't say for sure why this happens, not knowing any of your server-side code, but I assume it would occur if your PHP proxy script does not set the Content-Length HTTP response header correctly. If you were loading an actual image file, the web server would automatically set the header for you - in the case of your proxy script, it seems you have to take care of it yourself.
Anyway, you can make your loader script more error-proof by testing for NaN, and making sure the frame you jump to is never greater than 100:
var frame:int = isNaN (percentLoaded) || percentLoaded < 1 ? 1 :
percentLoaded > 100 ? 100 : percentLoaded;
progressBar.gotoAndStop(frame);
(I chose shorthand notation, but this is essentially the same as writing two if statements and an else).

calling function in a runtime loaded swf

Using AS3 / Flash CS4
Alright thanks to everyone who is reading this. My problem specifically I am designing a user interface with controls on it. 5 buttons rotate left, rotate right, zoom in, zoom out, and auto rotate. The interface in itself works fine, I can trace out button clicks, toggle the auto rotate button etc...
My program reads an xml file. Loads some images, fills an array with links for each image, and when the image is clicked a loader loads a swf from a URL and displays it on screen. No problem.
Now I originally had the zoom controls user interface in the runtime_loaded.fla library, and the mouse listeners in the same linked document class. The interface works with the movieClip in runtime_loaded.swf when it is in the same code.
Now to practice good coding, I decided to remove the UI from the runtime_loaded.fla and add it to the Main.fla. This is essential because the main is going to handle possible 100's of images/objects that each have their own unique swf to link too. If I decide to change out the look of the interface but leave the function calls the same, I could essentially put in as many as I want into the main.fla instead of the runtime_loaded.fla which I would have to do for every single object.
THE FILE STRUCTURE
Main.fla <- interface in the library. 5 mouse event functions. Inside each function calls
a property of loaded_swf (loaded_swf.rotateLeft, loaded_swf.rotateRight) etc...
Runtime_loaded.fla <- links specificObject.as in properties (AS3/CS4)
specificObject.as <- has 5 public static functions{ rotateRight, rotateLeft, zoomIn, zoomOut, toggleAutoRotate }
THE CODE
//showFlashBox
function showFlashBox(temp_string:String):void {
if(!flash_box_on){
var temp_top:uint = numChildren;
addChildAt(FlashBoxContainer,temp_top);
newXButton.addEventListener(MouseEvent.CLICK, flashBoxXClick);
1. addChild(new_loader);
2. var url:URLRequest = new URLRequest(temp_string);
new_loader.x = 0;
new_loader.y = 0;
new_loader.load(url);
3. new_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, gotSwf);
flash_box_on = true;
}
}
function gotSwf(e:Event){
4. //loaded_swf = e.target.content;
trace(e.target.content);
5. new_zoom_controls.button_minus.addEventListener(MouseEvent.CLICK, zoomOutFunction);
new_zoom_controls.button_plus.addEventListener(MouseEvent.CLICK, zoomInFunction);
new_zoom_controls.button_left.addEventListener(MouseEvent.CLICK, rotateLeftFunction);
new_zoom_controls.button_right.addEventListener(MouseEvent.CLICK, rotateRightFunction);
new_zoom_controls.button_rotate.addEventListener(MouseEvent.CLICK, toggleRotateFunction);
function rotateRightFunction(e:MouseEvent){
6. //loaded_swf.rotateRight();
}
function rotateLeftFunction(e:MouseEvent){
//loaded_swf.rotateLeft();
}
function zoomInFunction(e:MouseEvent){
//loaded_swf.zoomIn();
}
function zoomOutFunction(e:MouseEvent){
//loaded_swf.zoomOut();
}
function toggleRotateFunction(e:MouseEvent){
//loaded_swf.toggleAutoRotate();
if(new_zoom_controls.button_rotate.currentFrame == 1){
new_zoom_controls.button_rotate.gotoAndStop(2);
}
else new_zoom_controls.button_rotate.gotoAndStop(1);
}
new_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, gotSwf);
}
If you follow steps 1-6 you see my steps of loading the .swf, mouse event listeners and click handlers, then the object call of the var loaded_swf:Object;
public static function rotateLeft():void
{
object.yaw(animation_turning_speed);
}
public static function rotateRight():void
{
object.yaw(-animation_turning_speed);
}
if I run the main.fla and try to click the buttons. This happens.
ReferenceError: Error #1069: Property rotateRight not found on
ThreedsKU39web and there is no default value. at MethodInfo-82()
ReferenceError: Error #1069: Property rotateLeft not found on
ThreedsKU39web and there is no default value. at MethodInfo-83()
I actually stumbled upon the answer before I finished submitting this as I went through the code to copy it. But after spending a few hours of frustrating moments on this last night, I will post it to ensure the next guy doesn't meet the same demise.
The answer was in the function of the runtime-loaded swf class.
public static function rotateRight():void
{
object.yaw(-animation_turning_speed);
}
It turns out it only needs to be public function instead of public static.
Mainly human error as after the file was working, I attempted to copy the code over to all my other object files, and somehow static got back in there and messed it up. So for future reference when loading in the external swf, public function should do the trick. *Note that many of my variables were returning errors until being declared as public static though.