How to disable Rewind/Forward options? - actionscript-3

You know when you right-click on a scene and a bunch of options pop up? How do you disable the rewind and forward options (in-case a user accidentally presses on one of those options) because it screws my whole Flash game up.

You can disable most of the context menu with
stage.showDefaultContextMenu = false;
This will still leave the Settings and About sections though
There was a trick to completely remove the right click menu by catching up right click events on the stage, no idea if it still works with the current flash player versions:
stage.addEventListener(MouseEvent.RIGHT_CLICK, doNothing);
private function doNothing(e:MouseEvent):void
{
//do nothing...
}

Related

AS3 Making a button work on one scene and does nothing on all other scenes.

I basically have 50 buttons and 50 scenes. Each scene has a corresponding button that is "correct". When a user clicks the correct button, I want it to go to the next scene AND also make that button not-clickable anymore. I have everything functioning except for the not-clickable part and this is an issue because whenever i click on a state that already has been selected as the right answer, it'll jump me back to the question that was supposed to follow it. I'd show my code, but it is just 50 buttons and a buttonClick function and that's it.
Thanks in advance.
You could call
yourButton.removeEventListener(MouseEvent.CLICK,yourFunction);
or you could call
yourButton.mouseEnabled = false;
yourButton.mouseChildren = false;
Hard to help without any code.

Windows Phone disable back button when TimeSpanPicker has focus (i.e user choosing time span)

I am currently implementing a countdown timer for a windows phone app and I am having some trouble disabling the back button when the user is choosing a time span from the TimeSpanPicker. I only need to disable it when this is occurring and so it has to work fine apart from this.
I have the override OnBackKeyPress method with the following code inside it:
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
if(//user choosing duration using TimeSpanPicker)
{
e.Cancel = true;
}
base.OnBackKeyPress(e);
}
As you can see from the commented pseudo condition, I need a way of checking if the user is currently choosing a time span duration and if so disable the back button.
Many thanks in advance!
Your app will be rejected from the market if you completely disable the back button.
There are a number of reasons for this but the main one is that we want a consistent user experience across the platform. That's a great thing we have going for us. A user should be able to open your app and expect the buttons to function as they expect.
One acceptable reason to override the back button is if you are on a game screen and you want the game to pause. Another reason would be if you had a custom menu appear and the back button hides the menu. Both of these scenarios are obvious to the user.

How to programmatically navigate in a FlipView with swipe animations

The Windows Dev Center states regarding the UseTouchAnimationsForAllNavigation property:
The XAML FlipView control supports three modes of navigation; touch-based, button-based and programmatic. When a user navigates by touch, the FlipView items scroll smoothly into view. When you set this property to true, the same navigation animation occurs whether the navigation is touch-based, button-based and programmatic.
I'm currently navigating from my page's code behind by assigning the SelectedItem property of the FlipView:
FlipView.SelectedItem = FlipView.Items.Last();
However, the swipe animation does not show. How can I enable it?
Meanwhile, I was able to solve this problem. I have a button that triggers the navigation to the next FlipViewItem. This button however was placed in a FlipViewItem.
With my setup (touch device), nothing happend. Then I tried clicking the button with the mouse and it worked. After I disabled UseTouchAnimationsForAllNavigation, it also worked using touch input. In my tests, I placed the button outside of the FlipView and it did work using animations.
Here's the problem: When tapping the button, the navigation animation tries to start (SelectedIndex is set correctly), but stopped because the user blocks the animation by still touching the button. So, the navigation is cancelled and SelectionChanged reports the current page.
The solution is to set ManipulationMode of the Button to All. After that, you can't flip the FlipViewItem when touching the button, but the animation executes and it works like charm.
I solved the same problem in a different way. As Chliebel said, it is because your finger is still touching the control, so flipview cannot animate. So I gave a small break after before navigating. By the time user would have released the finger and it works !!!
await Task.Delay(100);
flipView.SelectedIndex += 1;
For me, ChristiaanV's answer has helped:
Animation only occurs when you navigate to the previous or next item
in the FlipView.
So I've set up a while loop to set the selected index to the previous / next one until I reach the desired page.
Example Code:
If you'd like to reach the first page:
while(flipView.SelectedIndex > 0)
{
flipView.SetValue(FlipView.SelectedIndexProperty, flipView.SelectedIndex - 1);
}
Here's a compact solution I found, similar to Bhawk1990's:
//nb is the index you wish to get to.
if (nb > flipview.SelectedIndex)
while (flipview.SelectedIndex != nb)
flipview.SelectedIndex++;
else if (nb < flipview.SelectedIndex)
while (flipview.SelectedIndex != nb)
flipview.SelectedIndex--;
I spent a couple of days figuring out why touch animation does not work when I programmatically change FlipView selected item when UseTouchAnimationsForAllNavigation="True".
I found a setting which controls animation machine wide. Somehow this setting was disabled:
Settings->Visual options->Play animations in Windows

How to save a button's position and settings?

I am trying to create an options menu for a game, where there are 2 buttons. One button is to disable all music, and the other is to disable all sound effects. When the button is clicked, it disappears with the .visible = false; code. The new button underneath is shown. When a person exits the game, I want the game to remember the settings, and which button is hidden.
Example: A person plays the game, but goes to options menu to disable sound. Sound is disabled, and the off button underneath is shown. The player exits the options menu, then exits the game. The player opens the game back up. The sound should still be disabled, and if the player goes to the options menu, the on button should still be invisible and the off button should be visible.
Could you please help me on how I can create this sort of system?
You should use 'SharedObject' class to store your data locally, then read it again on Startup.
See these examples as a start: example1, example2

Actionscript 3 - Synchronous Click Event

I am trying to build a custom modal dialog in flash. The way I chose to go about it is create a movie clip class with the UI for the dialog with a function to add buttons to it. I then size the ui after all the buttons are added and display it on the screen.
It works up to this point. Now I want whatever called this dialog to wait until a button is picked before the user can do anything else. Something along the lines of:
var dialog:MyDialog = new MyDialog();
dialog.addButton(new MyButton("Foo"));
dialog.addButton(new MyButton("Bar"));
var result:String = dialog.show(); // we will wait here
In the dialog.show I wish to show the movie clip and then wait for the user to click and of the buttons on the dialog before returning. The MouseEvent.CLICK event is asynchronous though so I don't know how to wait for it.
An alternative is creating a whole custom complete event for the dialog that is added to the screen that is calling the dialog which I can continue the logic in and have a boolean that disables other input, but that is a pretty big hassle and I've never done anything like it.
What your describing is a misconception of what synchronous and asynchronous is.
When the dialog comes up, you still want the user to be able to hit the dialog button. If the procedure was synchronous then the entire program would freeze as the routines for the mouse clicking actions would never arrive. Remember, flash is single threaded.
The thread that has the popup is sharing the same thread as the underlying app.
The easiest thing is just to have an event on the buttons that dispatch some close event that you can listen for in your application. No custom event classes are needed.
dispatchEvent(new Event("close"))
as an example.
If your worried about the user interacting with parts outside of the application, then you can simply draw a rectangle behind the popup with mouseEnabled true, or check out using Flex's model dialog classes.