Tag Archives: as3

AS Quiz # 3

Here is another quiz. Tomorrows quiz will be about design patterns…

Number of Questions : 5
Difficulty : Easy
Topic : General

Which of the below code snippets would cause a MovieClip located at 0 on the x axis to "ease-out" to 500 on the x axis?
Assume you have a MovieClip with the instance name "myClip" and that this code is happening on and enterFrame or in a timer





If you have a TextField nested within a MovieClip that has its buttonMode property set equal to true. Which of the following properties would you set to false on the TextField if you wanted to the hand cursor to appear when the mouse is over the TextField?





If you were to trace out the rotation property of a DisplayObject, you would notice that the values aren't simply from 0-360. Which of the following best describes the range of results you would get by tracing out the rotation property?







Given the below XML, how would you go about reading the name attribute of the leader node?
XML:
  1. <demo>
  2.   <users>
  3.      <team title="The Red Team">
  4.         <leader name="Joseph Brink" age="50" />
  5.         <player name="Nelson Smith" age "29" />
  6.         <player name="Joe Smith" age "29" />
  7.      </team>
  8.   </users>
  9. </demo>







If you want to load a text file, what class would you be most likely use?









Posted in Quiz | Also tagged , | 7 Comments

AS Quiz # 2

People seemed to do pretty well on yesterday’s quiz. I have lots of questions written that fall into that same category of being somewhere between beginner and intermediate level. I decided to write a trickier quiz for today. Tomorrow I’ll alternate back to some easier questions. This quiz is really more about operators and hex numbers than ActionScript…

Number of Questions : 5
Difficulty : Medium
Topic : Operators and Hexadecimal

Please go to AS Quiz # 2 to view the quiz
Posted in Quiz | Also tagged , , | 14 Comments

AS Quiz #1

This is the first in a hopefully long series of short ActionScript Quizzes I’ll be writing. This is just 6 simple questions… check it out….

Number of Questions : 6
Difficulty : Easy
Topic : General


Please go to AS Quiz #1 to view the quiz

Posted in Quiz | Also tagged , , | 16 Comments

Too Many Buttons

Actionscript:
  1. [SWF (width = 500, height = 500)]
  2.  
  3. var canvas:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0xFFFFFF);
  4. addChild(new Bitmap(canvas));
  5.  
  6. var indexCanvas:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0xFFFFFF);
  7.  
  8. var btnNum:int = 5000;
  9. var info:Array = [];
  10.  
  11. var brush:BitmapData = new BitmapData(10,10,false, 0xCCCCCC);
  12. var border:Shape = new Shape();
  13. border.graphics.lineStyle(2, 0x000000);
  14. border.graphics.drawRect(0,0,10,10);
  15. brush.draw(border);
  16.  
  17. var txt:TextField = TextField(addChild(new TextField()));
  18. with (txt) height = 20, width = 50, background = 0xFFFFFF, selectable = false
  19. var tf:TextFormat = new TextFormat();
  20. tf.align = TextFormatAlign.RIGHT;
  21. txt.border= true;
  22. txt.defaultTextFormat = tf;
  23.  
  24. var redRect:Shape = Shape(addChild(new Shape()));
  25. with (redRect.graphics) beginFill(0xFF0000), drawRect(0,0,10,10);
  26.                                              
  27. var pnt:Point = new Point();
  28. var r:Rectangle = new Rectangle(0,0,10,10);
  29. for (var i:int = 0; i <btnNum; i++){
  30.     pnt.x = r.x = int(Math.random() * stage.stageWidth);
  31.     pnt.y = r.y = int(Math.random() * stage.stageHeight);
  32.     indexCanvas.fillRect(r, i);
  33.     canvas.copyPixels(brush, brush.rect, pnt)
  34.     info[i] = [r.x, r.y, i];   
  35. }
  36.  
  37. addEventListener(Event.ENTER_FRAME, onCheckBtns);
  38. function onCheckBtns(evt:Event):void{
  39.    var currentIndex:int = indexCanvas.getPixel(mouseX, mouseY);
  40.    if (currentIndex != 0xFFFFFF){
  41.      var currentBox:Array = info[currentIndex]
  42.      redRect.visible = true;
  43.      redRect.x = currentBox[0];
  44.      txt.y = redRect.y = currentBox[1];
  45.      if (mouseX <txt.width){
  46.          tf.align = TextFormatAlign.LEFT;
  47.          txt.defaultTextFormat = tf;
  48.          txt.x = redRect.x + 10;
  49.      }else{
  50.          tf.align = TextFormatAlign.RIGHT;
  51.          txt.defaultTextFormat = tf;
  52.          txt.x = redRect.x - txt.width;
  53.      }
  54.      txt.text = currentBox[2];
  55.      txt.visible = true;
  56.    }else{
  57.      redRect.visible = false;
  58.      txt.visible = false;
  59.    }
  60. }

This is a simplified example of the technique discussed in yesterdays post. The idea is to use a BitmapData image to store index values for a large number of elements that need to be able to act as if the have MouseEvents. For a more detailed description of this technique see yesterdays post.

Have a look at the swf on wonderfl

Posted in BitmapData, arrays, misc | Also tagged , | Leave a comment