Object Glinting Method


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // INCLUDES...
  2. import flash.display.*;
  3. import com.greensock.*;
  4. import com.greensock.plugins.*;
  5. ////////////////////////////
  6.  
  7. public var glintMC:MovieClip = setUpGlint(objectToApplyGlintTo);
  8.  
  9. glint(glintMC, 2, 2, true);
  10.  
  11. public function setUpGlint(originalObj:*){
  12. var cloneBitmapData:BitmapData = new BitmapData(originalObj.width, originalObj.height, true, 0x000000);
  13. cloneBitmapData.draw(originalObj);
  14. var BmpClone:Bitmap = new Bitmap(cloneBitmapData);
  15. BmpClone.x = originalObj.x;
  16. BmpClone.y = originalObj.y;
  17. BmpClone.name = "BmpClone";
  18.  
  19. var cloneHolder:MovieClip = new MovieClip();
  20. cloneHolder.addChild(BmpClone);
  21. addChild(cloneHolder);
  22. cloneHolder.name = "assetForGlinting";
  23. TweenLite.to(cloneHolder, 0.01, {tint:0xFFFFFF, glowFilter:{blurX:7, blurY:7, alpha:1.35, strength:1, color:0xFFFFFF}});
  24.  
  25. var spot:MovieClip = new spotlight();
  26. spot.height = spot.width = originalObj.height*4;
  27. addChild(spot);
  28. spot.x = originalObj.x-(spot.width*0.75);
  29. spot.y = originalObj.y + originalObj.height/2;
  30. spot.name = "spot";
  31.  
  32. originalObj.cacheAsBitmap = cloneHolder.cacheAsBitmap = spot.cacheAsBitmap = true;
  33. cloneHolder.mask = spot;
  34.  
  35. var cloneClip:MovieClip = new MovieClip();
  36. cloneClip.addChild(originalObj);
  37. cloneClip.addChild(cloneHolder);
  38. cloneClip.addChild(spot);
  39. addChild(cloneClip);
  40. return cloneClip;
  41. }
  42.  
  43. public function glint(glintReadyMC:*, Delay=0, Duration=2, leftToRight=true){
  44. var spot:MovieClip = glintReadyMC.getChildByName("spot");
  45. var assetForGlinting = glintReadyMC.getChildByName("assetForGlinting").getChildByName("BmpClone");
  46. var tweenAmount:Number = assetForGlinting.width + spot.width*1.5;
  47. if(leftToRight){
  48. spot.x = assetForGlinting.x - (spot.width*0.75);
  49. } else {
  50. tweenAmount *= -1;
  51. spot.x = assetForGlinting.x + assetForGlinting.width + (spot.width*0.75);
  52. }
  53. TweenLite.to(spot, Duration, {delay:Delay, x:tweenAmount.toString()});
  54. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.