Conditionals

  • Conditional statements are in the form:
    • if(){}
    • conditions are between the parenthesis
      if(a>b)
    • consequences are between the curly braces
      {gotoAndPlay(3);}
    • if a=1 and b=2 then would we go anywhere?
    • Is the variable myScore greater than the allTimeHighScore
    • Does the value bytesLoaded = bytesTotal
    • Does the password = fluffy
  • Comparison operators evaluate the expressions on both sides of itself and returns a value of true or false.
  • When evaluated and found to be true then the function contained in curly brackets is performed. If false, then the function is ignored.
Comparison operators
== Equality  
=== strict equality(value and data type must be equal)  
< Less than  
> Greater than  
<= Less than or equal to  
>= Greater than or equal to  
!= != not equal to  
  • Consider the following code can you guess what will happen?:
    • var myShape:Shape=new Shape();
      myShape.graphics.lineStyle();
      myShape.graphics.beginFill(0xff0000);
      myShape.graphics.drawRect(100,100,50,50);
      addChild(myShape);
      stage.addEventListener(Event.ENTER_FRAME, moveSquare);
      function moveSquare(myevent:Event):void
      {
      myShape.x+=5;
      }
< >