views:

49

answers:

3

HEllo,

i try to do that in FlashBuilder (FlexProject)

protected function btn_detail_view_clickHandler(event:MouseEvent):void
        {
            CurrentState="Statistiques" || "PartMarche";
        }

But it's not working, i guess this is not the right syntax but what's the right syntax ? Thanks

PS: i want to when the state is equal to "statistiques" or "partMarche" when i click on the button, that the current state changes to Detail view ;)

+1  A: 

In ECMAScript languages, || is a short-circuit operator that will return the left-hand side expression result if it evaluates to a "truthy" value, or the right-hand side expression result otherwise. Non-empty strings always evaluate to truthy values, so the left-hand expression will always be returned here. The equivalent long-hand code to your example is:

if ("Statistiques")
    CurrentState = "Statistiques";
else
    CurrentState = "PartMarche";

This type of short circuit operator is used to set defaults to variables in certain situations:

CurrentState = PreviousState || "Some string";

In that example, if PreviousState is null or false or an empty string, CurrentState would be set to "Some string". If PreviousState is a string like "Some other string", CurrentState would be set to "Some other string".

Andy E
Thanks that is a complete, complex answer.If I understand the most of your anwser, ||is not the operator i'm looking for. But what operator to use then ? (i updated my post to tell you what i want to test)Thanks
Tristan
@Tristan: I'm not sure I understand fully, but I think you're looking for an ordinary `if` statement with an `||` and the equality operator: `if (CurrentState == "Statistiques" || CurrentState == "PartMarche") { CurrentState = "DetailView"; }`. Remember that a single `=` is an assignment operator, double `==` and triple `===` are equality and type-strict equality boolean operators respectively.
Andy E
It's that ! Thank you very much ;)
Tristan
+1  A: 

Thanks for clarifying what you want to do. For checking what CurrentState is, you need to test it with an if condition:

    if (CurrentState == "Statistiques" || CurrentState == "PartMarche")
    {
        // Of course, use the actual name of your detail view here
        CurrentState = "DetailView";
    }
BoltClock
Thank you verry much ;)
Tristan
A: 

Ok in fact i need to remove the .Statistiques to that code works in all the states

 click.Statistiques="btn_detail_view_clickHandler(event)"

Sorry i just went too fast by myself instead of finishing the tutorial.

Your answers will prevent me to ask the next question ! thank you ;)

Tristan