Reset/reuse a Flex Progress Bar - apache-flex

I'm using a progress bar to let a user know how much more live streaming video data is to be buffered before it starts playing. Have that much working fine.
Problem is, if the buffer gets used up, and I need to rebuffer, I can't seem to get the progress bar reset and visible again. Seems once it hits 100% on app start up it can't be reused. What am I missing here?
I'm catching the proper NetStream.netStatus events. The hook for the empty buffer is there and is executing. I'm just not seeing how I might redisplay and start a fresh bar there?
I've tried bar.visible = true and nothing appears. Also tried making a new one and setting visible each time the buffer is empty but no dice. Seems to just be ignored.

you can force the progress bar to reset "pBar.setProgress(0,100);", that will set it back to 0. just manually do that when you know that you have to rebuffer.

No, destroying the old one and making a new one with the same id.
That seems to be kind of working, but I'm not really sure what the best practice is here. Should I be making new ones each time I need to display one? Isn't there a way to simply recall the old one to the screen and reset it's progress to zero?

Related

How to get notified when changes in the document actually happens?

The following question is about RichTexFX. For standard JavaFX components, I've never had this issue before.
In my application, I am adding text content to the end of a GenericStyledArea (actually a subclass of it, but that should have no impact on the behaviour I am observing). Every time new content has been added to the end of the document, I scroll to the bottom so the new content is always in view. I use the following code to scroll to bottom (actually written in Kotlin, but I have translated it to Java below):
showParagraphAtTop(document.getParagraphs().size() - 1)
This almost always works. However, in some cases the screen will not show the newly added element. I have come to the conclusion that by the time showParagraphAtTop is called, some internal state in richtextfx has not been updated. This is because I added a button that I can click on to call the code above, and if I click it after the scroll failed, it scrolls to the bottom as expected.
I have tried various ways to work around this, but the only solution that works reliably is to do the following:
FxTimer.runLater(Duration.ofMillis(10), () -> showParagraphAtTop(getDocument().getParagraphs().size() - 1));
In other words, I force a short delay before actually scrolling the screen.
Even though the above works, it's incredibly unsatisfactory, and there should be some way to do this the right way. However, I have been unable to figure it out.
I saw another question (Autoscroll JavaFX TextFlow) which suggested the use of layout() prior to scrolling. This does not remove the problem, although it does appear to make it less common.

How to pause game running in background during asynchronous event?

I am creating a game in GMS2. I am using "show_message_async()" in my code. I know that when it is run, a message pops up on the screen and the game still runs in the background. However, I want the game to freeze in the background while the message pops up. Is it possible to do this? And if so how.
You should try looking up instance_deactivate_all(notme) and instance_activatie_all(notme)
https://docs.yoyogames.com/source/dadiospice/002_reference/objects%20and%20instances/instances/deactivating%20instances/index.html
This will disable all objects in a room except the object that's calling it (which should be the menu object that shows the message)
The only tricky part of it, it that it also disables drawing the objects. resulting in an empty screen. For this, you could either use a black screen, or draw a screenshot of the scene before they're disabled.
I agree with Steven's answer. To add on his answer about taking the screenshot of the game, you probably need to make a new surface, then use surface_copy from application_surface before deactivating the object.

How to create a "Please Wait" spinner while data is being imported

I am creating an Flex AIR app which imports data from a zip file into a sqlite db. I need to show a progress bar / "Please Wait" spinner animation so that the user waits till the operation completes.
I have tried to put a pop-up spinner animation but the problem is that the spinner stops spinning as soon as the database import queries start executing.
I need to run both the spinner code and the import code simultaneously rather than sequentially.
Thanks
The problem you are facing here is because Flex is a single threaded application. When you run large amounts of as processing, the thread does not update the UI, so your spinner stops spinning.
I think you can work around this by creating a Green Thread to handle your processing code if it can be sliced down. You can check here for an as3 implementation of the Green Thread.
I can provide some more info on implementing it if you need.
Your issue could be caused by the fact that Flash is single-threaded. Try replacing the import with at timer, to remove the cpu-intesive operation.
It that proves not to be the issue, a bit of code could speed up debugging :)
So - if you want just a spinner, you do not need any more data. If you want a progress bar, though, you will just have to know how much data is there (most likely the size of the zip will be precise enough). Then - have some Event.ENTER_FRAME listener in which you will take a part of the data, insert into table... And stop there. It will then show the animation of stuff. Try to see what amount of data is optimal... Most likely by adding a FPS meter there too, and if it goes too low, make the amount lower.
If you want the progress bar, just increment a variable with how many bytes were already parsed, and divide that by the total bytes - a ratio for progress bar. Rest same as spinner.

Timer event changes cursor

I have a timer event that updates certain things in my app (from a PHP Service) every 5 seconds. Every time this timer ticks, it makes the cursor blink to a clock and then back to the arrow. Since this is happening every 5 seconds, it gets pretty annoying. Is there a way for me to prevent the cursor from changing when the timer ticks?
UPDATE: I've figured out a work-around by setting a custom cursor with high priority (I just made a .png with a cursor in it). This works, but the cursor doesn't seem to move as smoothly as normal. Anyone know of a better solution?
I'm repeating my comment as an answer since it solved your issue, and adding a bit of detail. When you use the Data Connection wizard the default flag for showBusyCursor is "true" in order to prevent it you need to change this setting to "false".
I'm not sure what the FB4 wizard builds since I'm still using FB3, but if it's similar to the mxml httpService you just need to find the service in the .mxml file and you will see that attribute.
Now repeat after me. "All programmers make silly mistakes, especially when we are using new languages, I am no more of a moron than any other programmer" If, in a year, you look back on your code and don't say to yourself "what was I thinking" then you're probably doing something wrong.

Flex Post Event Screen Updates

I came across this topic today while investigating something very strange. Doing certain things in our Flex app can cause the number of frames rendered to rocket, from 12fps to ~30fps: loaded animations start playing at high speed and the GUI starts to lock up.
Since everything I've read on Flex/Flash hammers home the point "the frame rate is capped at the fps set in the top level app", it seems the only way these extra renders can be happening is due to some events causing them (no programmatic changes to the stage's framerate are done anywhere). Since it only happens when I put my update logic in the ENTER_FRAME handler, I'm trying to figure out what might be happening which to apparently causing Flex to go render-crazy.
Hypothesis: something in my update function is triggering an immediate screen update, this raises another ENTER_FRAME immediately, which means my update loop gets called, which triggers another immediate screen update, ...
We have Flex components used in our GUI, if this is a factor. I don't really know where to go next on this.
Clarifications:
When I say things speed up, there
are two ways this manifests.
Firstly, my ENTER_FRAME handler gets
called far more often.
Secondly, a
loaded Flash SWF with a looping
animation built in suddenly speeds
up to te point it looks silly.
I am not using updateAfterEvent, I only
found this existed when researching
this problem. Apparently, some
events on Sprite subclasses
automatically call this and I wonder
if that's the root cause.
I am not doing any direct messsing about with rendering at all. Background animations play automatically as they have timelines built-in from CS3 authoring, all our update function does is change the position of DisPlayObjects or add/remove them etc
Update:
I added a label to my app to print out stage.frameRate, and discovered at certain times, it suddenly changes from 12 to 1000 (the maximum allowed value). While it was trivial to add a line to my ENTER_FRAME handler to reset it that's hardly a big help.
Also, even doing this, the rendering is all messed up. Certain actions (like raising an Alert popup) make it all spring back into life.
Unfortunately, I am not able to view the source of the Stage class to set a breakpoint on the setter property.
That's very interesting about the Flex loading 'set to 1000fps' thing. What we have are several Flex applications which all provide a common interface. A master app is in charge of loading these modules as required through the SWFLoader class. However, the loading process already takes into account the delayed loading... when the SWF loads we then wait for the APPLICATION_COMPLETE from the SystemManager. Once this is received, shouldn't the applications completion have occurred?
Flex sets the frame rate to 1000 during "phased instantiation" of Flex components, which occurs only during initial load of a flex swf. This allows it to build all components very quickly.
Are you waiting for the Flex app to be fully loaded and constructed? You should be waiting for FlexEvent.CREATION_COMPLETE before working with your Flex content.
If you would like a reference to where this occcurs, look in the Flex LayoutManager class, line 326 (using Flex SDK 3.0.194161), in the setter for the property usePhasedInstantiation.
Update:
APPLICATION_COMPLETE should have you covered for the initial load.
This actually happens any time components are created directly from MXML. So there are a few other cases to look for. Are you using any Repeaters? Do you use any navigation containers that are building their children on demand?
One thing I'm not clear on - are you seeing that the actual screen refreshes are occurring faster than the published framerate? Or is it that your animations are moving faster but the screen refreshes are unchanged? (i.e., it used to move 10 pixels per second, but now it moves faster than that, regardless of how often the screen is drawn.)
An easy way to check this would be to try publishing your content at 1 fps. It should be clear whether the screen is redrawing once per second, but animated elements are being moved more frequently than that, or whether the screen is actually updating more frequently.
If the latter, are you using any updateAfterEvent() methods in your code? This can cause actual screen refreshes to occur faster than the published framerate. It shouldn't affect ENTER_FRAME events though. You should still only get one of those per frame update.
Alternately, are the things you're animating just Sprites and so on, or are you implementing them as Flex components, and trying to redraw them with invalidate() methods and RENDER events and so on?
If you could clarify a few of these points in the question the answer might be clearer. Thanks...
Thanks for the clarifications. If a loaded clip with a animation (I assume you mean a frame animation) is speeding up, then that certainly sounds like something is changing your playback framerate, as opposed to other things that could be going on. With that said it's not a problem I've seen crop up before, but I do think there are some things you could try that ought to narrow down where the problem is:
You might as well try tracing out stage.frameRate during the speed-up. Presumably nothing ought to be changing your framerate, but since that would explain your issues you might as well rule it out.
Try removing as many GUI components as possible and seeing if the problem still occurs, if it's possible to trigger the problem without them.
One sanity check you could try, if it's feasible, is to copy some of the contents of your game into a fresh project and try it there. Sometimes mysterious issues like this happen because some class or SWC is being imported somewhere that everyone forgot about.
You could try driving your code from a different event. For example, as far as I know driving it from Event.EXIT_FRAME or Event.FRAME_CONSTRUCTED ought to look the same, but if it doesn't then that's a hint. Alternately, you could try driving it from something like a keyboard event or MouseEvent.MOUSE_MOVE. Then if updates occur even though you're not firing events, you'll know something else is driving things besides your event loop.
Those are the things I'd try, anyway. Hope you track it down...

Resources