如何在特定框架上运行外部actionscript文件?

时间:2014-06-14 01:58:57

标签: actionscript-3 flash

对于模糊的问题,我们深表歉意。关键是我想在指定的框架上运行一个外部actionscript(.as)文件,这样它就不会运行,除非我点击了主菜单中的开始按钮。这是为了确保游戏精灵不会出现在主菜单上。我已经尝试了#34;在框架中导出类"选项,但它不会工作。动作脚本已设置为文档类。我没有在时间轴上放置代码。

我游戏的外部动作代码:

package 
{
import flash.display.*;
import flash.events.*;
import flash.utils.*;
import flash.media.*;
import com.greensock.*;

public class image_match extends MovieClip
{

    private var first_tile:images;
    private var second_tile:images;
    private var pause_timer:Timer;
    var imagedeck:Array = new     

Array(1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12);

    var theFirstCardSound:FirstCardSound = new FirstCardSound();
    var theMissSound:MissSound = new MissSound();
    var theMatchSound:MatchSound = new MatchSound();

    var playerScore:Number = 0;

    public function image_match()
    {
        trace(this.currentFrame);

        for (x = 1; x <= 6; x++)
        {
            for (y = 1; y <= 4; y++)
            {

                var random_card = Math.floor(Math.random() *  
imagedeck.length);
                var tile:images = new images  ;
                tile.col = imagedeck[random_card];
                imagedeck.splice(random_card,1);
                tile.gotoAndStop(13);

                tile.x = 95;
                tile.y = 145;
                tile.x +=  (x - 1) * 122;
                tile.y +=  (y - 1) * 132;


tile.addEventListener(MouseEvent.CLICK,tile_clicked);
                tile.addEventListener(MouseEvent.MOUSE_OVER, glow);
                tile.addEventListener(MouseEvent.MOUSE_OUT, noGlow);
                tile.buttonMode = true;
                addChild(tile);
            }
        }


    }
    //Function to create glow effect.
    function glow(event:MouseEvent):void
    {

        TweenMax.to(event.currentTarget, 0.3, {glowFilter:{color:0x0000ff, 
alpha:1, blurX:10, blurY:10,strength:0.7}});
    }

    //Function to remove glow effect.
    function noGlow(event:MouseEvent):void
    {
        TweenMax.to(event.currentTarget, 0.5, {glowFilter:{alpha:0}});
    }

    public function tile_clicked(event:MouseEvent)
    {

        var clicked:images = event.currentTarget as images;


        if ((first_tile == null))
        {
            first_tile = clicked;
            theFirstCardSound.play();
            first_tile.gotoAndStop(clicked.col);
        }
        else if (((second_tile == null) && first_tile != clicked))
        {
            second_tile = clicked;
            second_tile.gotoAndStop(clicked.col);
            if (first_tile.col == second_tile.col)
            {

                theMatchSound.play();
                pause_timer = new Timer(1000,1);

pause_timer.addEventListener(TimerEvent.TIMER_COMPLETE,remove_tiles);
                pause_timer.start();
                playerScore +=  200;
            }
            else
            {
                theMissSound.play();
                pause_timer = new Timer(1000,1);

pause_timer.addEventListener(TimerEvent.TIMER_COMPLETE,reset_tiles);
                pause_timer.start();
                playerScore -=  20;
            }

        }

        updateScore();
    }





public function updateScore():void
    {
        scoreText.text = playerScore.toString();
        trace("Score: " + scoreText.text);
    }


    public function reset_tiles(event:TimerEvent)
    {
        first_tile.gotoAndStop(13);
        second_tile.gotoAndStop(13);
        first_tile = null;
        second_tile = null;

pause_timer.removeEventListener(TimerEvent.TIMER_COMPLETE,reset_tiles);
    }
    public function remove_tiles(event:TimerEvent)
    {
        removeChild(first_tile);
        removeChild(second_tile);
        first_tile = null;
        second_tile = null;

pause_timer.removeEventListener(TimerEvent.TIMER_COMPLETE,remove_tiles);
    }


}
}

1 个答案:

答案 0 :(得分:0)

您发布的外部代码是一个类。这意味着在创建它的实例之前,它中的代码将不会运行。将实例创建移动到您希望执行代码的框架,您应该获得所要求的行为。

如果您不知道实例是什么,请查找包含以下内容的行:

...=new match_it();
addChild(...);

这两行创建match_it类的实例并将其添加到显示层。将它们移动到相关框架。可能需要移动更多代码,但由于您没有粘贴实际的实例化,这是我无法确定的。

我也建议看一下as3类的基础知识,它会让你的生活变得更轻松,这是一个教程:

http://www.untoldentertainment.com/blog/2009/08/25/tutorial-understanding-classes-in-as3-part-1/