Perl SWF :: Builder disappears into image

I am working on a script to create swf files with I / O images.

This is my code:

my %CONFIG = (
    'scriptURI' => "data.js",
    'imageFolder' => "images/",
    'outputFileName' => 'testImg.swf',
    'delay' => 3,                       # delay between images
    'fps'   => 10,
    'fadeFrame' => 10                   # 1 second fade in/out
);

sub addImgToMovie {
    my $img = shift;
    my $frameNo = shift;
    my $movie = shift;
    my $movieClip = $movie -> new_mc();
    my $jpeg = $movieClip -> new_jpeg($img);
    $jpeg -> place(Frame => 1);

    my $mc_i = $movieClip -> place(Frame => $frameNo);  

    my $onloadScript = sprintf("
        this._alpha = %d;
        this.apf = %f;
        this.frameIndex = %d;
        this.fadeOutFrameIndex = %d;
        ", 0, 100 / $CONFIG{'fadeFrame'}, 1, $CONFIG{'delay'} * $CONFIG{'fps'} - $CONFIG{'fadeFrame'});
    $mc_i -> onClipEvent('Load') -> compile($onloadScript);

    my $onEnterFrameScript = "
        this.frameIndex += 1;
        if ((this._alpha < 100) && (this.frameIndex < this.fadeOutFrameIndex)) {
            this._alpha += this.apf;
        } else if (this.frameIndex > this.fadeOutFrameIndex) {
            this._alpha -= this.apf;
        }
    ";
    $mc_i -> onClipEvent('EnterFrame') -> compile($onEnterFrameScript);
    return $movie;
}

my $movie = SWF::Builder -> new(
    FrameRate => $CONFIG{'fps'},
    FrameSize => [0, 0, 180, 163],
    BackgroundColor => 'ffffff'
);

my $img = $CONFIG{'imageFolder'} . "adimage1.jpg";
$movie = addImgToMovie($img, 1, $movie);
$movie -> save($CONFIG{'outputFileName'});

      

The script outputs the SWF file, but it only fades and the image disappears once, then I have a blank image.

I'm debugging a file and I find out that the frameIndex is constantly growing, so I suspect that onEnterFrame keeps playing, so the movie clip never stops.

Can anyone help me with this problem. I want the movie clip to stop after the image has completely disappeared.

+3


source to share


1 answer


I think it is missing a call to complete the script after it completes. What happens if you do the following?

    my $onEnterFrameScript = "
    this.frameIndex += 1;
    if ((this._alpha < 100) && (this.frameIndex < this.fadeOutFrameIndex)) {
        this._alpha += this.apf;
    } else if (this.frameIndex > this.fadeOutFrameIndex) {
        this._alpha -= this.apf;
        if (this._alpha <= 0){
            this._visible=false;
            delete this.onEnterFrame;
        }
    }
";

      



Notice the call to "delete this.onEnterFrame"

+2


source







All Articles