Flash中添加符号到AS3中的舞台

时间:2014-05-05 13:43:53

标签: actionscript-3 flash class object adobe

我正在尝试将我的图书馆中的符号添加到舞台上。出于某种原因,当我运行代码时,舞台上没有出现任何对象,但我也没有收到任何错误。我无法提供所有的代码,因为它非常长,但我会为阅读的人提供足够的知识,以便对我正在尝试做的事情有所了解。

基本上,主as3文件的开头如下:

包{

import flash.display.*;
import flash.events.*;
import flash.ui.*;
import flash.media.*;
import flash.net.*;

public class NewFrogMod extends MovieClip 

{

        var oneHit:Boolean;
        var twoHit:Boolean;
        var threeHit:Boolean;
        var fourHit:Boolean;
        var fiveHit:Boolean;
        var sixHit:Boolean;
        var sevenHit:Boolean;
        var eightHit:Boolean;
        var nineHit:Boolean;
        var tenHit:Boolean;
        var elevenHit:Boolean;
        var twelveHit:Boolean; 
        var thirteenHit:Boolean; 
        var fourteenHit:Boolean; 

        var score:uint;


        var frog1:Frog;
        var truck1:Truck;
        var truck2:Truck;
        var truck3:Truck;
        var car1:Car;
        var car2:Car;
        var log1:Logs;
        var log2:Logs;
        var log3:Logs;
        var log4:Logs;
        var turtle1:Turtles;
        var turtle2:Turtles;
        var z1:Zfrog;
        var z2:Zfrog;
        var z3:Zfrog;
        var z4:Zfrog;
        var z5:Zfrog;


    public function NewFrogMod()

    {

    var score = 0;


    frog1 = new Frog();
    truck1 = new Truck();
    truck2= new Truck();
    truck3 = new Truck();
    car1 = new Car();
    car2 = new Car();
    log1 = new Logs();
    log2 = new Logs();
    log3 = new Logs();
    log4 = new Logs();
    turtle1 = new Turtles();
    turtle2 = new Turtles();
    z1 = new Zfrog();
    z2 = new Zfrog();
    z3 = new Zfrog();
    z4 = new Zfrog();
    z5 = new Zfrog();


    addChild(frog1);
    addChild(truck1);
    addChild(truck2);
    addChild(car1);
    addChild(car2);
    addChild(log1);
    addChild(log2);
    addChild(log3);
    addChild(turtle1);
    addChild(turtle2);
    addChild(z1);
    addChild(z2);
    addChild(z3);
    addChild(z4);
    addChild(z5);

    frog1.x = 238;
    frog1.y = 373;

    truck1.x = 0;
    truck1.y = 252;

    truck2.x = 205;
    truck2.y = 252;

    car1.x = 82;
    car1.y = 175;

    car2.x = 363;
    car2.y = 175;

    log1.x = 22;
    log1.y = 51;

    log2.x = 355;
    log2.y = 51;

    log3.x = 43;
    log3.y = 102;

    log4.x = 292;
    log4.y = 102;


    turtle1.x = 241;
    turtle1.y = 81;

    turtle2.x = 508;
    turtle2.y = 125;

    z1.x = 200;
    z1.y = 250;

    z2.x = 300;
    z2.y = 350;

    z3.x = 100;
    z3.y = 150;

    z4.x = 100;
    z4.y = 250;

    z5.x = 200;
    z5.y = 150;

之后还有更多......

现在,为了让您了解我如何设置对象,以下是其中一些对象的代码:

包{

import flash.display.MovieClip;
import flash.events.Event;

public class Car extends NewFrogMod{

    public function Car() 
    {
        addEventListener(Event.ENTER_FRAME, Enter4);
    }
    function Enter4(event:Event):void
    {
        this.x += 3;

    }
}

}

包{

import flash.display.MovieClip;
import flash.events.Event;

public class Truck extends NewFrogMod{

    public function Truck() 
        {

        addEventListener(Event.ENTER_FRAME, Enter5);
        }
    function Enter5(event:Event):void {

        if(this.hitTestObject(frog1))
           {
                health1.width -= 5;   


            }
    }


}

}

我也尝试使用这些文件扩展MovieClip,这也不起作用。任何肝脏都是非常重要的。谢谢!

2 个答案:

答案 0 :(得分:0)

确保添加了movieclip的父类NewFrogMod已经添加到舞台中。

同时确保每个库符号,例如卡车,已与其班级相关联:

  1. 右键单击库中的符号,然后从菜单中选择“属性”。
  2. 选中“为ActionScript导出'。
  3. ”框
  4. 在“课程”字段中,输入您的卡车类的完整课程路径(在您的情况下只需“卡车”#39;)。可以忽略基本字段类,因为您的Truck类已经扩展了MovieClip。
  5. 或者,将NewFrogMod指定为主时间轴的文档类:

    1. 左键单击舞台的空白部分,转到“属性”检查器,然后在“类”字段中输入NewFrogMod。

答案 1 :(得分:0)

我认为您可能在指定位置之前添加了对象。尝试将addChild函数移动到x和y坐标下方。