Skip to content

Instantly share code, notes, and snippets.

@neves
Created February 10, 2009 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neves/61702 to your computer and use it in GitHub Desktop.
Save neves/61702 to your computer and use it in GitHub Desktop.
package
{
import flash.display.*
import flash.events.*
public class Botao extends SimpleButton
{
var estado = "up"
function Botao()
{
iniciar_parado()
sincronizar_up_over()
}
/**
* faz a animação up, começar parada no final
*/
function iniciar_parado()
{
var state = upState
state.gotoAndStop(state.totalFrames)
state = overState
state.gotoAndStop(1)
}
function sincronizar_up_over()
{
addEventListener(Event.ENTER_FRAME, observar_estado)
}
function observar_estado(e)
{
//trace((overState as MovieClip).currentFrame)
//trace(overState.stage)
var novo_estado = overState.stage == null ? "up" : "over"
if (novo_estado != estado)
{
estado = novo_estado
sincronizar()
}
/* versão com if
if (overState.stage == null)
novo_estado = "up"
else
novo_estado = "down"
*/
}
function sincronizar()
{
var over = overState
var over_posicao = over.currentFrame / over.totalFrames
var up = upState
var up_posicao = up.currentFrame / up.totalFrames
var frame
if (estado == "up")
{
frame = Math.ceil((1-over_posicao)*up.totalFrames)
if (frame == 0) frame = 1
up.gotoAndPlay(frame)
}
else // over
{
frame = Math.ceil((1-up_posicao)*over.totalFrames)
if (frame == 0) frame = 1
over.gotoAndPlay(frame)
}
trace(frame)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment