Posted By

adrianparr on 02/02/11


Tagged

flip as3 Spin paper papersprite rotationY matrix3d soulwire


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

kure69
merritt212
makeyko


AS3 PaperSprite Demo (Click and flip)


 / Published in: ActionScript 3
 

URL: http://blog.soulwire.co.uk/code/open-source/two-sided-planes-in-flash-player-10

Here you must have some movieclips in your library with class names of "CardFront1", "CardBack1", "CardFront2", "CardBack2", "CardFront3", "CardBack3"

  1. package
  2. {
  3. import flash.display.MovieClip;
  4. import flash.events.Event;
  5. import flash.events.MouseEvent;
  6. import flash.utils.getDefinitionByName;
  7.  
  8. import soulwire.display.PaperSprite;
  9. import com.greensock.*;
  10. import com.greensock.easing.*;
  11.  
  12. public class paperSpriteDemo extends MovieClip
  13. {
  14. private const NUM_OF_CARDS:int = 3;
  15. private const TWEEN_DURATION_SECS:Number = 1.5;
  16. private const EASING_PARAMS_ARRAY:Array = [0, 1.5];
  17.  
  18. private const CARD_ARRAY_1:Array = ["CardFront1", "CardBack1", 200, 200];
  19. private const CARD_ARRAY_2:Array = ["CardFront2", "CardBack2", 550, 200];
  20. private const CARD_ARRAY_3:Array = ["CardFront3", "CardBack3", 900, 200];
  21.  
  22. private var arrayOfPaperSprites:Array;
  23.  
  24. public function paperSpriteDemo()
  25. {
  26. arrayOfPaperSprites = new Array();
  27.  
  28. for (var i:int = 0; i < NUM_OF_CARDS; i++ ) {
  29. var paperSprite:PaperSprite = new PaperSprite();
  30.  
  31. var FrontClass:Class = getDefinitionByName(this["CARD_ARRAY_" + (i + 1)][0]) as Class;
  32. paperSprite.front = new FrontClass();
  33.  
  34. var BackClass:Class = getDefinitionByName(this["CARD_ARRAY_" + (i + 1)][1]) as Class;
  35. paperSprite.back = new BackClass();
  36.  
  37. paperSprite.buttonMode = true;
  38. paperSprite.mouseChildren = false;
  39.  
  40. paperSprite.x = this["CARD_ARRAY_" + (i + 1)][2];
  41. paperSprite.y = this["CARD_ARRAY_" + (i + 1)][3];
  42.  
  43. paperSprite.addEventListener(MouseEvent.CLICK, onCardClick);
  44. addChild(paperSprite);
  45. arrayOfPaperSprites.push(paperSprite);
  46. }
  47.  
  48. stage.invalidate();
  49. }
  50.  
  51. private function onCardClick(e:MouseEvent):void
  52. {
  53. var card:PaperSprite = PaperSprite(e.currentTarget);
  54. if (card.isFrontFacing) {
  55. TweenLite.to(card, TWEEN_DURATION_SECS, {rotationY:180, ease:Elastic.easeOut, easeParams:EASING_PARAMS_ARRAY, onComplete:showingBack, onCompleteParams:[card]});
  56. } else {
  57. TweenLite.to(card, TWEEN_DURATION_SECS, {rotationY:0, ease:Elastic.easeOut, easeParams:EASING_PARAMS_ARRAY, onComplete:showingFront, onCompleteParams:[card]});
  58. }
  59. }
  60.  
  61. private function showingFront(card:PaperSprite):void
  62. {
  63. trace("Showing the front of card: " + card);
  64. }
  65.  
  66. private function showingBack(card:PaperSprite):void
  67. {
  68. trace("Showing the back of card: " + card);
  69. }
  70.  
  71.  
  72. }
  73.  
  74. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: chaanu on July 19, 2011

wow

You need to login to post a comment.