将一个动作脚本导入另一个动作脚本

时间:2013-05-08 22:24:35

标签: actionscript-3

我在我的项目中走到了尽头,我需要为我孩子的幼儿园小组制作一个flash游戏。这是一个简单的拖放游戏,所有功能都很好,直到我尝试将一些代码插入时间轴中的按钮(游戏功能来自.as文件)。

我设法用按钮功能创建另一个.as文件,但是如何从第一个类调用它?

游戏功能类:

package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.URLRequest; 

public class Spajalica extends MovieClip
{
    private var xPos:int;
    private var yPos:int;
    private var correctCount:int = 0;
    private var totalCount:int = 18;


    public function Spajalica():void
    {
        addListeners(s1, s2, s3, i1, i2, i3, n1, n2, n3, p1, p2, p3, b1, b2, b3, f1, f2, f3);
    }

    private function getPosition(target:Object):void
    {
        xPos = target.x;
        yPos = target.y;
    }

    private function dragObject(e:MouseEvent):void
    {
        getPosition(e.target);

        e.target.startDrag(true);
    }

    private function stopDragObject(e:MouseEvent):void
    {
        if (e.target.hitTestObject(getChildByName(e.target.name + "Target")))
        {
            e.target.x = getChildByName(e.target.name + "Target").x;
            e.target.y = getChildByName(e.target.name + "Target").y;
            //deactivate object
            e.currentTarget.removeEventListener(MouseEvent.MOUSE_DOWN, dragObject);
            e.currentTarget.removeEventListener(MouseEvent.MOUSE_DOWN, stopDragObject);
            //increment correct count;
            correctCount++;
            // totalCount is the amount of solutions the user must solve to proceed
            if (correctCount == totalCount)
            {
                nextScene();
            }
        }
        else
        {
            e.target.x = xPos;
            e.target.y = yPos;
        }

        e.target.stopDrag();
    }

    private function addListeners(... objects):void
    {
        for (var i:int = 0; i < objects.length; i++)
        {
            objects[i].addEventListener(MouseEvent.MOUSE_DOWN, dragObject);
            objects[i].addEventListener(MouseEvent.MOUSE_UP, stopDragObject);
        }
    }
}

}

这是我的按钮类:

package testis
{

import flash.display.MovieClip;
import fl.display.ProLoader;
import flash.events.MouseEvent;
import flash.net.URLRequest;


public class testis extends MovieClip
{
    public var fl_ProLoader_5:ProLoader;


    public function testis() {

back_btn.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF_5);


//This variable keeps track of whether you want to load or unload the SWF
var fl_ToLoad_5:Boolean = true;

function fl_ClickToLoadUnloadSWF_5(event:MouseEvent):void
 {
if(fl_ToLoad_5)
{
    fl_ProLoader_5 = new ProLoader();
    fl_ProLoader_5.load(new URLRequest("main.swf"));
    addChild(fl_ProLoader_5);
}
else
{
    fl_ProLoader_5.unload();
    removeChild(fl_ProLoader_5);
    fl_ProLoader_5 = null;
}
// Toggle whether you want to load or unload the SWF
fl_ToLoad_5 = !fl_ToLoad_5;
}

    }

}

}

如何“连接”那些?

Thanx提前!!

1 个答案:

答案 0 :(得分:0)

只需找到您要呼叫的功能并参考按钮:

例如:

buttonthathasbuttonclass.removeEventListener(buttonthathasbuttonclass.somefunction);

确保该功能是公开的。

相关问题