Flex: Right click button causes state change - apache-flex

Right click on a Spark Button triggers a state change from "over" to "up".
Instead I would like the state to be "down", so the button behaves the same on left or rightclick.
Is this possible?

Yes it is!
var b:Boolean;
protected function rightMouseDown(e:MouseEvent):void {
b = true;
}
protected function rightMouseUp(e:MouseEvent):void {
b = false;
}
override public function setCurrentState(stateName:String, playTransition:Boolean = true):void {
if (!b) {
super.setCurrentState(stateName, playTransition);
} else {
super.setCurrentState(...);
}
}

Related

Style.Visibility doesnt let element do animation?

I have two functions which should hide and make my element (Image), whose id is "Brandish":
hideBrandish(): void {
document.getElementById('Brandish').style.visibility = 'hidden';
}
showBrandish(): void {
document.getElementById('Brandish').style.visibility = 'visible';
}
Now I have a function, that calls first this.showBrandish().
Then I have a function, that calls the .className = 'skillimage', which moves the image per #keyframes:
this.moveSkillImage(); {
if (this.chosenHero.skill.name === 'Brandish') {
document.getElementById('Brandish').className = 'skillImage';
}
}
Finally I call hideBrandish().
The problem is that my animation isn't processing, instead my image just gets hidden. Why is that?

Mouse Button click wont register

var note : String = "blah"
function OnGUI()
{
if (IsPaused)
{
GUI.Box (Rect (580,20,100,210), "Pause");
if (GUI.Button (Rect (590,130,80,20), "Info"))
{
Debug.Log("I pressed it");
GUI.Button (Rect (450, 200, Screen.width/2, Screen.height/2), info);
}
else if (GUI.Button (Rect (590,160,80,20), "Quit"))
{
Application.Quit();
}
else if(GUI.Button (Rect(590,190,80,35), "Back"))
{
IsPaused = false;
GetComponent(LookAtMouse).enabled = true;
}
}
This is my function for my GUI, as you can see, i have three buttons within it. The quit and back buttons work fine but when i click the info button, nothing will register.
I put GUI.Button (Rect (450, 200, Screen.width/2, Screen.height/2), info); This line of code outside the if statement to check if it works and it will but when its inside the statement i get nothing.
Can anyone tell me why?
var displayInfo : boolean = false;
if (IsPaused)
{
GUI.Box (Rect (580,20,100,210), "Pause");
displayInfo = GUI.Toggle(Rect (590,130,80,20), displayInfo, "Info");
{
if(displayInfo)
{
GUI.Button (Rect (450, 200, Screen.width/2, Screen.height/2), info);
}
}
#rutter thanks for the idea, i used the boolean idea you had and created a toggle to check, if the info is displayed, create the instance of the textfield when it was toggled on

Setting TabContainer Active Tab dynamically by visibility

I'm using AjaxControlToolkit TabContainer and dynamically setting TabPanel visiblility. When active tab is is hidden (dynamically) the whole Tab Control is hidden, so to avoid this I've written small method like this (setting first visible tab as Active Tab)
private void SetActiveTab()
{
if (tabControl1.Tabs[0].Visible)
{
tabControl1.ActiveTabIndex =0;
return;
}
if (tabControl1.Tabs[1].Visible)
{
tabControl1.ActiveTabIndex = 1;
return;
}
...
}
But this feels like but inefficient/ugly code for me..., Is there a better way of doing this...?
Choose any
for (int tabIndex = 0; tabIndex < TabContainer1.Tabs.Count; tabIndex++)
{
if(TabContainer1.Tabs[tabIndex].Visible)
{
TabContainer1.ActiveTabIndex = tabIndex;
break;
}
}
foreach (TabPanel tab in TabContainer1.Tabs)
{
if (tab.Visible)
{
TabContainer1.ActiveTab = tab;
break;
}
}
var firstVisibleTab = TabContainer1.Tabs.OfType<TabPanel>().FirstOrDefault(tab => tab.Visible);
if (firstVisibleTab != null)
{
TabContainer1.ActiveTab = firstVisibleTab;
}
BTW for such quetions better use Code Review site: Code Review

XNA button hovering

I have a button in my game. and I want to make it to change to other button image when mouse hover on it and change back when the mouse not in the button.
the problem is when the mouse went out from the button rectangle area, it not change back to the first image
my code like this :
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
MouseState mouseState;
mouseDiBack = false;
mouseState = Mouse.GetState();
if (new Rectangle(mouseState.X, mouseState.Y, 1, 1).Intersects(backButtonRectangle))
{
backButton = backButtonHilite;
}
if ((mouseState.LeftButton == ButtonState.Pressed) &&
(new Rectangle(mouseState.X, mouseState.Y, 1, 1).Intersects(backButtonRectangle)))
{
mouseDiBack = true;
}
}
public override void Draw(GameTime gameTime)
{
spriteBatch.Draw(ScoreBG, ScoreBGRectangle, Color.White);
spriteBatch.Draw(backButton, backButtonRectangle, Color.White);
base.Draw(gameTime);
}
}
}
any idea how I to do it...?
Fairly simple solution, you didn't set the image back on the case where the mouse is not hovering.
if (new Rectangle(mouseState.X, mouseState.Y, 1, 1).Intersects(backButtonRectangle))
{
backButton = backButtonHilite;
}
else
{
backButton = originalImage; //whatever your Texture2D object may be called
}
Don't expect the machine to know that you want to switch back! Machines are stupid! ..Ok, it's actually because you overwrote the value of the variable and didn't reset it.
You are not setting your backButton back to what it used to be when the mouse moves out of the scope area. Take a look at the code below, and notice the added ELSE statement in your Update function.
defaultBackButton = backButton; //Save the default back button somewhere outside your update function
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
MouseState mouseState;
mouseDiBack = false;
mouseState = Mouse.GetState();
if (new Rectangle(mouseState.X, mouseState.Y, 1,1).Intersects(backButtonRectangle))
{
backButton = backButtonHilite;
}
else
{
backButton = defaultBackButton;
}
if ((mouseState.LeftButton == ButtonState.Pressed) && (new Rectangle(mouseState.X, mouseState.Y, 1, 1).Intersects(backButtonRectangle)))
{
mouseDiBack = true;
}
}
As mentioned by Jon you need to set your original texture back when the mouse has left the rectangle.
bool mouseOverBackButton =
mouseX >= buttonRectangle.Left && mouseX <= buttonRectangle.Right &&
mouseY >= buttonRectangle.Top && mouseY <= buttonRectangle.Bottom;
backgroundTexture = mouseOverBackButton ? mouseOverTexture: mouseAwayTexture;
mouseDiBack = mouseState.LeftButton == ButtonState.Pressed && mouseOverBackButton;

How do I maintain focus position in UpdatePanel after page partial post back

I have four controls in a page with update panel. Initially mouse focus is set to first control. When I partially post back the page to server the focus automatically moves to first control from the last focused control from the control I have tabbed down to. Is there any way to maintain the last focus?
Take a look at Restoring Lost Focus in the Update Panel with Auto Post-Back Controls:
The basic idea behind the solution is to save the ID of the control
with input focus before the update panel is updated and set input
focus back to that control after the update panel is updated.
I come with the following JavaScript which restores the lost focus in
the update panel.
var lastFocusedControlId = "";
function focusHandler(e) {
document.activeElement = e.originalTarget;
}
function appInit() {
if (typeof(window.addEventListener) !== "undefined") {
window.addEventListener("focus", focusHandler, true);
}
Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(pageLoadingHandler);
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoadedHandler);
}
function pageLoadingHandler(sender, args) {
lastFocusedControlId = typeof(document.activeElement) === "undefined"
? "" : document.activeElement.id;
}
function focusControl(targetControl) {
if (Sys.Browser.agent === Sys.Browser.InternetExplorer) {
var focusTarget = targetControl;
if (focusTarget && (typeof(focusTarget.contentEditable) !== "undefined")) {
oldContentEditableSetting = focusTarget.contentEditable;
focusTarget.contentEditable = false;
}
else {
focusTarget = null;
}
targetControl.focus();
if (focusTarget) {
focusTarget.contentEditable = oldContentEditableSetting;
}
}
else {
targetControl.focus();
}
}
function pageLoadedHandler(sender, args) {
if (typeof(lastFocusedControlId) !== "undefined" && lastFocusedControlId != "") {
var newFocused = $get(lastFocusedControlId);
if (newFocused) {
focusControl(newFocused);
}
}
}
Sys.Application.add_init(appInit);
I find this more elegant:
(function(){
var focusElement;
function restoreFocus(){
if(focusElement){
if(focusElement.id){
$('#'+focusElement.id).focus();
} else {
$(focusElement).focus();
}
}
}
$(document).ready(function () {
$(document).on('focusin', function(objectData){
focusElement = objectData.currentTarget.activeElement;
});
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(restoreFocus);
});
})();

Resources