0

我有一个五彩纸屑生成器,我很想将它添加到我的 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]} );
    }
  }
}
4

1 回答 1

0

Now I understand your problem.

First of all, I suggest to never write code on the timeline, except simple stuff like stop() or gotoAndPlay("loop").

The easiest way to achieve what you want is to do the following:

  1. Make a blank MovieClip in Flash IDE Ctrl + F8
  2. Give it a linkage like this: Add linkage for flash symbol
  3. Then click the edit button (marked with a red rectangle)
  4. Open in Flash Professional if asked
  5. Save the file in your .FLA directory and copy the contents of your Main.as file into this file
  6. Remove the package name ("com.pixeljunkyard")
  7. Change the public class Main extends Sprite to public class ConfettiContainer extends MovieClip and import flash.display.MovieClip

Now you have a class ConfettiContainer which does the same stuff that you Main.as file did. Don't forget to copy anything that this Main.as class uses from stage to your ConfettiContainer MovieClip.

You can now create and use it like this:

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

P.S. If you can't see Export for Actionscript option when creating a Symbol in Flash, click Advanced.

于 2013-07-09T14:25:39.707 回答