actionscript 3 - Creating a Spinning Wheel in as3 that displays text when stopping -


i trying create spinning wheel display coupon code when stops on particular color. right displays color @ bottom of page add in specific coupon codes associated each wheel snippet appear when wheel stops in advance!

here current code:

package   {     import flash.display.sprite;         import flash.display.shape;     import flash.events.mouseevent;     import flash.events.event;     import com.greensock.tweenmax;  public final class main extends sprite {     private var speed:number = 0;     private var paddles:vector.<sprite> = new vector.<sprite>();     private var line:shape;     private var lastpaddle:string;      public final function main():void     {         paddles.push(wheel.p1, wheel.p2, wheel.p3, wheel.p4, wheel.p5, wheel.p6);         listeners('add');     }             private final function listeners(action:string):void      {         if(action == 'add')         {             stage.addeventlistener(mouseevent.mouse_down, startdraw);             stage.addeventlistener(mouseevent.mouse_up, spinwheel);         }         else         {             stage.removeeventlistener(mouseevent.mouse_down, startdraw);             stage.removeeventlistener(mouseevent.mouse_up, spinwheel);         }     }      private final function startdraw(e:mouseevent):void     {         line = new shape();         addchild(line);          line.graphics.moveto(mousex, mousey);         line.graphics.linestyle(5, 0x00000, 0.3);         stage.addeventlistener(mouseevent.mouse_move, drawline);     }      private final function drawline(e:mouseevent):void     {         line.graphics.lineto(mousex, mousey);     }      private final function spinwheel(e:mouseevent):void     {         stage.removeeventlistener(mouseevent.mouse_move, drawline);         listeners('rm');          speed = line.height * 0.1;          removechild(line);         line = null;          stage.addeventlistener(event.enter_frame, spin);     }      private final function spin(e:event):void     {         /* rotate wheel */          wheel.rotationz += speed;          /* detect value */          for(var i:int = 0; < 6; i++)         {             if(indicator.harea.hittestobject(paddles[i]))             {                 lastpaddle = paddles[i].name;             }         }          speed -= 0.1;          if(speed <= 0)         {             stage.removeeventlistener(event.enter_frame, spin);             speed = 0;             run(lastpaddle);             listeners('null');         }     }      function run(action:string):void     {         switch(action)         {             case 'p1':                 tweenmax.to(colormc, 0.5, {colortransform:{tint:0x644d9b, tintamount:1}});                 break;             case 'p2':                 tweenmax.to(colormc, 0.5, {colortransform:{tint:0xffcc00, tintamount:1}});                 break;             case 'p3':                 tweenmax.to(colormc, 0.5, {colortransform:{tint:0x4789c2, tintamount:1}});                 break;             case 'p4':                 tweenmax.to(colormc, 0.5, {colortransform:{tint:0xf15d5d, tintamount:1}});                 break;             case 'p5':                 tweenmax.to(colormc, 0.5, {colortransform:{tint:0x90cc6c, tintamount:1}});                 break;             case 'p6':                 tweenmax.to(colormc, 0.5, {colortransform:{tint:0xf29c69, tintamount:1}});                 break;             }         }     } } 

edit:: updated code per suggestions added wheel.p1.addchild(mytext); @ end in function run(action:string):void area. correct way of doing or there better way. unable have text show in live version.

package  {     import flash.display.sprite;     import flash.display.shape;     import flash.events.mouseevent;     import flash.events.event; import com.greensock.tweenmax; import flash.text.textformat; import flash.text.textfield;  public final class main extends sprite; {     private var speed:number = 0;     private var paddles:vector.<sprite> = new vector.<sprite>();     private var line:shape;     private var lastpaddle:string;      public final function main():void     {         paddles.push(wheel.p1, wheel.p2, wheel.p3, wheel.p4, wheel.p5, wheel.p6);         listeners('add');     }      private final function listeners(action:string):void     {         if (action == 'add')         {             stage.addeventlistener(mouseevent.mouse_down, startdraw);             stage.addeventlistener(mouseevent.mouse_up, spinwheel);         }         else         {             stage.removeeventlistener(mouseevent.mouse_down, startdraw);             stage.removeeventlistener(mouseevent.mouse_up, spinwheel);         }     }      private final function startdraw(e:mouseevent):void     {         line = new shape();         addchild(line);          line.graphics.moveto(mousex, mousey);         line.graphics.linestyle(5, 0x00000, 0.3);         stage.addeventlistener(mouseevent.mouse_move, drawline);     }      private final function drawline(e:mouseevent):void     {         line.graphics.lineto(mousex, mousey);     }      private final function spinwheel(e:mouseevent):void     {         stage.removeeventlistener(mouseevent.mouse_move, drawline);         listeners('rm');          speed = line.height * 0.1;         removechild(line);         line = null;          stage.addeventlistener(event.enter_frame, spin);     }      private final function spin(e:event):void     {         /* rotate wheel */          wheel.rotationz +=  speed;          /* detect value */          (var i:int = 0; < 6; i++)         {             if (indicator.harea.hittestobject(paddles[i]))             {                 lastpaddle = paddles[i].name;             }         }          speed -=  0.1;          if (speed <= 0)         {             stage.removeeventlistener(event.enter_frame, spin);             speed = 0;             run(lastpaddle);             listeners('null');         }     }      function run(action:string):void     {         switch (action)         {             case 'p1' :                 tweenmax.to(colormc, 0.5, {colortransform:{tint:0x644d9b, tintamount:1}});                 var mytext:textfield = new textfield();                 mytext.text = "10per";                 wheel.p1.addchild(mytext);                  mytext.textcolor = 0xff0000;                 mytext.x = 350;                 mytext.y = 485;                 break;             case 'p2' :                 tweenmax.to(colormc, 0.5, {colortransform:{tint:0xffcc00, tintamount:1}});                 break;             case 'p3' :                 tweenmax.to(colormc, 0.5, {colortransform:{tint:0x4789c2, tintamount:1}});                 break;             case 'p4' :                 tweenmax.to(colormc, 0.5, {colortransform:{tint:0xf15d5d, tintamount:1}});                 break;              case 'p5' :                 tweenmax.to(colormc, 0.5, {colortransform:{tint:0x90cc6c, tintamount:1}});                 break;              case 'p6' :                 tweenmax.to(colormc, 0.5, {colortransform:{tint:0xf29c69, tintamount:1}});                 break;            }         }     } } 

here final code worked how needed to! helped.

package  { import flash.display.sprite; import flash.display.shape; import flash.events.mouseevent; import flash.events.event; import com.greensock.tweenmax; import flash.text.textformat; import flash.text.textfield;  public final class main extends sprite {     private var speed:number = 0;     private var paddles:vector.<sprite> = new vector.<sprite>();     private var line:shape;     private var lastpaddle:string;      public final function main():void     {         paddles.push(wheel.p1, wheel.p2, wheel.p3, wheel.p4, wheel.p5, wheel.p6);         listeners('add');     }      private final function listeners(action:string):void     {         if (action == 'add')         {             stage.addeventlistener(mouseevent.mouse_down, startdraw);             stage.addeventlistener(mouseevent.mouse_up, spinwheel);         }         else         {             stage.removeeventlistener(mouseevent.mouse_down, startdraw);             stage.removeeventlistener(mouseevent.mouse_up, spinwheel);         }     }      private final function startdraw(e:mouseevent):void     {         line = new shape();         addchild(line);          line.graphics.moveto(mousex, mousey);         line.graphics.linestyle(5, 0x00000, 0.3);         stage.addeventlistener(mouseevent.mouse_move, drawline);     }      private final function drawline(e:mouseevent):void     {         line.graphics.lineto(mousex, mousey);     }      private final function spinwheel(e:mouseevent):void     {         stage.removeeventlistener(mouseevent.mouse_move, drawline);         listeners('rm');          speed = line.height * 0.1;         removechild(line);         line = null;          stage.addeventlistener(event.enter_frame, spin);     }      private final function spin(e:event):void     {         /* rotate wheel */          wheel.rotationz +=  speed;          /* detect value */          (var i:int = 0; < 6; i++)         {             if (indicator.harea.hittestobject(paddles[i]))             {                 lastpaddle = paddles[i].name;             }         }          speed -=  0.1;          if (speed <= 0)         {             stage.removeeventlistener(event.enter_frame, spin);             speed = 0;             run(lastpaddle);             listeners('null');         }     }      function run(action:string):void     {         switch (action)         {             case 'p1' :                 tweenmax.to(colormc, 0.5, {colortransform:{tint:0x644d9b, tintamount:1}});                      var myformat:textformat = new textformat();                         myformat.size = 30;                       var mytext:textfield = new textfield();                         mytext.defaulttextformat = myformat;                         mytext.text = "10% off order coupon code:perc10";                         addchild(mytext);                          mytext.textcolor = 0xffffff;                         mytext.width = 624;                         mytext.height = 41;                         mytext.x = 43;                         mytext.y = 457;                 break;             case 'p2' :                 tweenmax.to(colormc, 0.5, {colortransform:{tint:0xffcc00, tintamount:1}});                     var myformat:textformat = new textformat();                         myformat.size = 27;                       var mytext:textfield = new textfield();                         mytext.defaulttextformat = myformat;                         mytext.text = "$5 off when spend $20+ coupon code:5iveoff";                         addchild(mytext);                          mytext.textcolor = 0x6d6d6d;                         mytext.width = 676;                         mytext.height = 38;                         mytext.x = 22;                         mytext.y = 459;                  break;             case 'p3' :                 tweenmax.to(colormc, 0.5, {colortransform:{tint:0x4789c2, tintamount:1}});                     var myformat:textformat = new textformat();                         myformat.size = 30;                       var mytext:textfield = new textfield();                         mytext.defaulttextformat = myformat;                         mytext.text = "20% off order coupon code:2zero";                         addchild(mytext);                          mytext.textcolor = 0xffffff;                         mytext.width = 618;                         mytext.height = 41;                         mytext.x = 43;                         mytext.y = 458;                   break;             case 'p4' :                 tweenmax.to(colormc, 0.5, {colortransform:{tint:0xf15d5d, tintamount:1}});                     var myformat:textformat = new textformat();                         myformat.size = 27;                       var mytext:textfield = new textfield();                         mytext.defaulttextformat = myformat;                         mytext.text = "$10 off when spend $30+ coupon code:10doll";                         addchild(mytext);                          mytext.textcolor = 0xffffff;                         mytext.width = 672;                         mytext.height = 38;                         mytext.x = 20;                         mytext.y = 459;                  break;              case 'p5' :                 tweenmax.to(colormc, 0.5, {colortransform:{tint:0x90cc6c, tintamount:1}});                     var myformat:textformat = new textformat();                         myformat.size = 30;                       var mytext:textfield = new textfield();                         mytext.defaulttextformat = myformat;                         mytext.text = "15% off order coupon code:fifperc";                         addchild(mytext);                          mytext.textcolor = 0xffffff;                         mytext.width = 618;                         mytext.height = 41;                         mytext.x = 50;                         mytext.y = 458;                  break;              case 'p6' :                 tweenmax.to(colormc, 0.5, {colortransform:{tint:0xf29c69, tintamount:1}});                     var myformat:textformat = new textformat();                         myformat.size = 27;                       var mytext:textfield = new textfield();                         mytext.defaulttextformat = myformat;                         mytext.text = "$15 off when spend $40+ coupon code:fifdolla";                         addchild(mytext);                          mytext.textcolor = 0xffffff;                         mytext.width = 672;                         mytext.height = 38;                         mytext.x = 15;                         mytext.y = 459;;                 break;         }     } } 

}


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -