Flash Component Button Behavior

From Director Online Wiki
Jump to: navigation, search

Description

Enables basic control over a flash component Button sprite

Director MX 2004, Director 11

Lingo

-- AstrO Controls :: Flash Button
-- version 1.0b5-20Jul08
-- Created by Toby De Ieso
-- Modified by Toby De Ieso
 
 
property pSprite
property pMember
property pObject
property pActive
 
property pStartEnabled
property pButtonLabel
property pStartEmphasized 
property pStartToggle 
property pStartSelected 
property pEventEnabled
property pEventCode
property pEventStopSounds
property pThemeColor
property pFontFamily
property pFontSize
property pFontStyle
property pFontWeight
property pTextDecoration
property pFontColor
property pFontDisabledColor
 
 
on isOKToAttach me, aSpriteType, aSpriteNum
  tReturn = FALSE
  if sprite(aSpriteNum).member.type = #flashComponent then tReturn = TRUE
  return tReturn
end
 
 
on getPropertyDescriptionList me
  tList = [:]
 
  tList.addProp(#pButtonLabel, [#comment:"label:",#format:#string,#default:"Button"])
  tList.addProp(#pStartEnabled, [#comment:"enable:",#format:#boolean,#default:TRUE])
  tList.addProp(#pStartEmphasized, [#comment:"emphasized:",#format:#boolean,#default:FALSE])
  tList.addProp(#pStartToggle, [#comment:"toggle:",#format:#boolean,#default:FALSE])
  tList.addProp(#pStartSelected, [#comment:"selected:",#format:#boolean,#default:FALSE])
  tList.addProp(#pEventEnabled, [#comment:"run code on click:",#format:#boolean,#default:TRUE])
  tList.addProp(#pEventCode, [#comment:"code:",#format:#string,#default:"trace(sprite(me.spriteNum),me)"])
  tList.addProp(#pEventStopSounds, [#comment:"stop all sounds before running code:",#format:#boolean,#default:FALSE])
 
  tList.addProp(#pThemeColor, [#comment:"themeColor:",#format:#string,#default:"haloGreen",#range:["haloGreen","haloBlue","haloOrange"]])
  tList.addProp(#pFontFamily, [#comment:"fontFamily:",#format:#string,#default:"_sans"])
  tList.addProp(#pFontSize, [#comment:"fontSize:",#format:#integer,#default:12])
  tList.addProp(#pFontStyle, [#comment:"fontStyle:",#format:#string,#default:"normal",#range:["normal","italic"]])
  tList.addProp(#pFontWeight, [#comment:"fontWeight:",#format:#string,#default:"normal",#range:["normal","bold"]])
  tList.addProp(#pTextDecoration, [#comment:"textDecoration:",#format:#string,#default:"normal",#range:["normal","underline"]])
  tList.addProp(#pFontColor, [#comment:"color:",#format:#color,#default:color(11,51,60)])
  tList.addProp(#pFontDisabledColor, [#comment:"disabledColor:",#format:#color,#default:color(132,131,132)])
 
  return tList
end
 
 
on beginSprite me
  pSprite = sprite(me.spriteNum)
  pMember = pSprite.member
  pActive = FALSE
  pType = pMember.name
 
  pMember.label = pButtonLabel
  pMember.selected = pStartSelected 
  pMember.eventPassMode = #passNever
  pMember.buttonsEnabled = TRUE
  pMember.actionsEnabled = TRUE
  pMember.toggle = pStartToggle 
 
  pSprite.ink = 36
end
 
 
on exitFrame me
  if not(pActive) then
    pObject = pSprite.getVariable("_root",FALSE)
 
    pSprite.enabled = pStartEnabled
    pSprite.emphasized = pStartEmphasized
    pSprite.setStyle("themeColor",pThemeColor)
    pSprite.setStyle("fontFamily",pFontFamily)
    pSprite.setStyle("fontSize",pFontSize)
    pSprite.setStyle("fontStyle",pFontStyle)
    pSprite.setStyle("fontWeight",pFontWeight)
    pSprite.setStyle("textDecoration",pTextDecoration)
    pSprite.setStyle("color",("0x" & pFontColor.hexString().char[2..7]))
    pSprite.setStyle("disabledColor",("0x" & pFontDisabledColor.hexString().char[2..7]))
 
    pActive = TRUE
  end if
end 
 
on click(me)
  if pActive and pEventEnabled then
    if pEventStopSounds then
      repeat with i = 1 to 8
        _sound.channel(i).stop()
      end repeat
    end if
    do pEventCode
  end if
end