0

我的项目陷入了死胡同,我需要为我孩子的幼儿园小组制作一个 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;
}

    }

}

}

如何“连接”那些?

提前谢谢!!

4

1 回答 1

0

只需找到您要调用的函数并引用该按钮:

前任:

buttonthathasbuttonclass.removeEventListener(buttonthathasbuttonclass.somefunction);

并确保该功能是公开的。

于 2013-05-09T01:26:29.073 回答