Dynamic Glowing Effect

  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

i know, this can be done now using Flash 8, but for the previous version i think it`s nice. Not to complicated, but the effect looks good. All you need for this tutorial is 2 mc-s in the first frame, called "frog" and "bottle" (this code can be extended to any number of mc-s, just add the onRollOver and onRollOut code for them, exactly like in the code below).
Place this code in the first frame of the timeline (or in any frame, but make sure the mc-s you use are there too).
Code: [ Select ]
var m_bCreate:Boolean = true;
var m_iGlowIndex:Number = 0; // the current glowIndex
var m_iFrameCount:Number = 0;
var m_bStartGlow:Boolean = false;

//variables that can be changed
var m_strNewName:String = "frog"; // just a string, not important
var m_CrtMC:MovieClip = this.frog; // just a string, not important
var m_iMaxGlow:Number = 4; // maximum glow
var m_iAlpha:Number = 0.6; // alpha step
var m_iStartAlpha:Number = 10; // starting alpha for the first glow
var m_iGlowSpeed:Number = 2; // glow speed - the higher the slower
var m_iGlowXGrow:Number = 4; // glow speed - the higher the slower
var m_iGlowYGrow:Number = 2; // glow speed - the higher the slower

function CreateGlow(iIndex:Number, target:MovieClip, newName:String)
{
    var crtMC = target.duplicateMovieClip(newName + iIndex, iIndex);
    var my_color = new Color(crtMC);
    my_color.setRGB(0xB0F7FF); // glowing color
    
    crtMC._alpha = m_iStartAlpha - m_iAlpha * iIndex;
    crtMC._width += iIndex * m_iGlowXGrow;
    crtMC._height += iIndex * m_iGlowYGrow;
    crtMC._x -= iIndex * m_iGlowXGrow / 2;
    crtMC._y -= iIndex * m_iGlowYGrow; // change here m_iGlowYGrow to grow on bottom too
}

onEnterFrame = function()
{
    if (m_bStartGlow)
    {
        m_iFrameCount ++;        
        if (m_iFrameCount >= m_iGlowSpeed)
        {
            m_iFrameCount = 0;
            if (m_iGlowIndex < m_iMaxGlow && m_bCreate)
            {
                CreateGlow(m_iGlowIndex, m_CrtMC, m_strNewName);
                m_iGlowIndex ++;
            }
            else
            {
                m_bCreate = false;
                this[m_strNewName + m_iGlowIndex].removeMovieClip();
                m_iGlowIndex --;
                if (m_iGlowIndex == 0)
                    m_bCreate = true;
            }
        }
    }
}

function ResetGlow()
{
    var iIndex:Number;
    for (iIndex = 0; iIndex <= m_iGlowIndex; iIndex ++)
    {
        this[m_strNewName + iIndex].removeMovieClip();
    }
    
    m_iGlowIndex = 0;
    m_bCreate = true;
}

bottle.onRollOver = function()
{
    m_CrtMC = this;
    m_bStartGlow = true;
}
bottle.onRollOut = function()
{
    m_bStartGlow = false;
    ResetGlow();
}

frog.onRollOver = function()
{
    m_CrtMC = this;
    m_bStartGlow = true;
}
frog.onRollOut = function()
{
    m_bStartGlow = false;
    ResetGlow();
}
stop();
  1. var m_bCreate:Boolean = true;
  2. var m_iGlowIndex:Number = 0; // the current glowIndex
  3. var m_iFrameCount:Number = 0;
  4. var m_bStartGlow:Boolean = false;
  5. //variables that can be changed
  6. var m_strNewName:String = "frog"; // just a string, not important
  7. var m_CrtMC:MovieClip = this.frog; // just a string, not important
  8. var m_iMaxGlow:Number = 4; // maximum glow
  9. var m_iAlpha:Number = 0.6; // alpha step
  10. var m_iStartAlpha:Number = 10; // starting alpha for the first glow
  11. var m_iGlowSpeed:Number = 2; // glow speed - the higher the slower
  12. var m_iGlowXGrow:Number = 4; // glow speed - the higher the slower
  13. var m_iGlowYGrow:Number = 2; // glow speed - the higher the slower
  14. function CreateGlow(iIndex:Number, target:MovieClip, newName:String)
  15. {
  16.     var crtMC = target.duplicateMovieClip(newName + iIndex, iIndex);
  17.     var my_color = new Color(crtMC);
  18.     my_color.setRGB(0xB0F7FF); // glowing color
  19.     
  20.     crtMC._alpha = m_iStartAlpha - m_iAlpha * iIndex;
  21.     crtMC._width += iIndex * m_iGlowXGrow;
  22.     crtMC._height += iIndex * m_iGlowYGrow;
  23.     crtMC._x -= iIndex * m_iGlowXGrow / 2;
  24.     crtMC._y -= iIndex * m_iGlowYGrow; // change here m_iGlowYGrow to grow on bottom too
  25. }
  26. onEnterFrame = function()
  27. {
  28.     if (m_bStartGlow)
  29.     {
  30.         m_iFrameCount ++;        
  31.         if (m_iFrameCount >= m_iGlowSpeed)
  32.         {
  33.             m_iFrameCount = 0;
  34.             if (m_iGlowIndex < m_iMaxGlow && m_bCreate)
  35.             {
  36.                 CreateGlow(m_iGlowIndex, m_CrtMC, m_strNewName);
  37.                 m_iGlowIndex ++;
  38.             }
  39.             else
  40.             {
  41.                 m_bCreate = false;
  42.                 this[m_strNewName + m_iGlowIndex].removeMovieClip();
  43.                 m_iGlowIndex --;
  44.                 if (m_iGlowIndex == 0)
  45.                     m_bCreate = true;
  46.             }
  47.         }
  48.     }
  49. }
  50. function ResetGlow()
  51. {
  52.     var iIndex:Number;
  53.     for (iIndex = 0; iIndex <= m_iGlowIndex; iIndex ++)
  54.     {
  55.         this[m_strNewName + iIndex].removeMovieClip();
  56.     }
  57.     
  58.     m_iGlowIndex = 0;
  59.     m_bCreate = true;
  60. }
  61. bottle.onRollOver = function()
  62. {
  63.     m_CrtMC = this;
  64.     m_bStartGlow = true;
  65. }
  66. bottle.onRollOut = function()
  67. {
  68.     m_bStartGlow = false;
  69.     ResetGlow();
  70. }
  71. frog.onRollOver = function()
  72. {
  73.     m_CrtMC = this;
  74.     m_bStartGlow = true;
  75. }
  76. frog.onRollOut = function()
  77. {
  78.     m_bStartGlow = false;
  79.     ResetGlow();
  80. }
  81. stop();
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 7 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.