我是 AS3 的新手。
我想为 MC 中的某些对象提供“类”(意思是类似类的 css)翻转。所以我可以自动创建一个 rollOver 淡出所有声明为 rollOver 对象的对象。
jQuery 示例
$("#myObject .rollOverObject").animate(...);
在 AS3 中实现类似功能的最佳方式是什么?
提前致谢并致以最诚挚的问候。
最佳答案
AS3 中没有 CSS 类这样的东西。但是,您可以做的是在 MC 上创建一个 EventListener
并在其中制作动画。它看起来像这样。
for (var i : int = 0; i < mcContainer.numChildren; i++)
{
// reference to a child of the container
var mcChild:MovieClip = mcContainer.getChildAt(i) as MovieClip;
// validate by name
if(mcChild.name == "something you want to check")
{
mcChild.addEventListener(MouseEvent.ROLL_OVER, onMcRollOver);
}
}
function onMcRollOver(event:MouseEvent) : void
{
// create a reference to the MovieClip that is rolled over
var mcTarget:MovieClip = event.currentTarget as MovieClip;
// do what you like with the mcTarget
mcTarget.alpha = 0.5;
}
如果您不再使用 MovieClips
,或者不再需要 ROLL_OVER
监听器,您可以通过类似的方式删除这些监听器。
for (var i : int = 0; i < mcContainer.numChildren; i++)
{
// reference to a child of the container
var mcChild:MovieClip = mcContainer.getChildAt(i) as MovieClip;
// validate by name
if(mcChild.hasEventListener(MouseEvent.ROLL_OVER))
{
mcChild.removeEventListener(MouseEvent.ROLL_OVER, onMcRollOver);
}
}
快速 Google search可以帮助您进一步学习。
关于actionscript-3 - AS3 类 CSS 对象类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8668180/