如何在单个AS3影片剪辑中使用文档类?

时间:2013-07-09 04:14:01

标签: actionscript-3 class generator document

我有一个五彩纸屑生成器,我正在添加到我的Flash文件中的单个影片剪辑。剪辑被屏蔽了,我希望在五彩纸屑上方显示一些图形和文字(也将在背景图层上方)。

我购买了一个不错的脚本,并修改了它以使用一些原创的五彩纸屑艺术品,但我无法弄清楚如何在一个影片剪辑中使用这个类(或更改它使用)。粘贴下面的课程。我一直在强调这一点几个小时,任何帮助将不胜感激。

package com.pixeljunkyard 
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import caurina.transitions.*;
    import fl.motion.Color;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;

public class Main extends Sprite
{
    //Create Heart Instance
    private var hearts:Heart;

    //Amount of hearts
    private var totalHearts:Number = 30;

    //Falling Speed
    private var speed:Number = 1.5;

    //Constructor
    public function Main() 
    {
        //Align top left for screen aspect ratio
        stage.align = StageAlign.TOP_LEFT;
        stage.scaleMode = StageScaleMode.NO_SCALE;

        //Loop through the amount of heart to be created
        for (var i = 0; i < totalHearts; i++)
        {
            //Create new heart
            var heart = new Heart();

            //Set Random value
            var randScale:Number = randRange(50, 100);
            var randRotation:Number = randRange( -180, 180);
            var randRotationY:Number = randRange( -360, 360);

            //Random position and scale
            heart.x = randRange(0, stage.stageWidth);
            heart.y = randRange( -stage.stageHeight, stage.stageHeight);
            heart.scaleX = randScale/100;
            heart.scaleY = randScale/100;

            //Name each heart with the number of creation
            heart.name = "heart" + i;

            var Low : int = 1;
            var High : int = 8;
            var myRandomNumber:int = Math.floor(Math.random()*(1+High-Low))+Low;


            heart.gotoAndStop(myRandomNumber);

            //Add eventlisteners for interactions
            heart.addEventListener(MouseEvent.ROLL_OVER, hit_heart);
            heart.addEventListener(Event.ENTER_FRAME, change_shade);

            //Initial Animation
            Tweener.addTween(heart, {time:randRange(1,5)/speed, rotation:randRotation,rotationY:randRotationY,y:stage.stageHeight+(heart.height/2)+20, transition:"linear", onComplete:rebirth,onCompleteParams:[heart]} );

            //Add to Stage
            addChildAt(heart, i);

        }
    }

    //Change shade to give lighting effect
    private function change_shade(e:Event):void
    {
        //New color instance
        var c:Color = new Color();
        //Set properties
        c.brightness = e.target.rotation / 300;

        //Apply color to heart
        e.target.transform.colorTransform = c;

    }

    //Random Function
    private function randRange(min:Number, max:Number):Number 
    {
        var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
        return randomNum;
    }

    //Interactive animation
    private function hit_heart(e:Event):void
    {
        Tweener.addTween(e.target, { time:randRange(1,3), rotationY:e.target.rotationY+180 } );
    }

    //Reset heart to top of the screen once fallen
    private function rebirth($heart:Heart):void
    {
        $heart.x = randRange(0, stage.stageWidth);
        $heart.y = -$heart.height;

        Tweener.addTween($heart, {time:randRange(1,5)/speed, rotation:randRange(-180,180),y:stage.stageHeight+($heart.height/2)+20, transition:"linear", onComplete:rebirth,onCompleteParams:[$heart]} );
    }
  }
}

1 个答案:

答案 0 :(得分:0)

现在我理解你的问题了。

首先,我建议永远不要在时间轴上编写代码,除了stop()gotoAndPlay("loop")之类的简单内容。

实现目标的最简单方法是执行以下操作:

  1. 在Flash IDE中空白MovieClip Ctrl + F8
  2. 给它一个这样的链接: Add linkage for flash symbol
  3. 然后单击编辑按钮(标有红色矩形)
  4. 如果询问,请在Flash Professional中打开
  5. 将文件保存在.FLA目录中,并将Main.as文件的内容复制到此文件中
  6. 删除包名称(“com.pixeljunkyard”)
  7. public class Main extends Sprite更改为public class ConfettiContainer extends MovieClip并导入flash.display.MovieClip
  8. 现在你有一个类ConfettiContainer,它与你的Main.as文件做了同样的事情。不要忘记将此Main.as类从舞台使用的任何内容复制到您的ConfettiContainer MovieClip

    您现在可以像这样创建和使用它:

    var confetti:ConfettiContainer = new ConfettiContainer();
    addChild(confetti);
    

    P.S。如果您在Flash中创建Export for Actionscript时看不到Symbol选项,请点击Advanced