【问题标题】:AS3 OOP inheritance and functionsAS3 OOP 继承和函数
【发布时间】:2013-03-28 11:53:23
【问题描述】:

我希望有人可以帮助我解决我在尝试将我创建的谜题中的 as3 代码集成到我的游戏 FLA 文件中时遇到的问题。

在 Game.fla 中,我有一个名为 Engine 的主类,它包含从库中调用多个空影片剪辑到舞台,然后使用库中的资产填充每个影片剪辑。每个影片剪辑都有自己的关联类。

我已经在一个单独的文件中创建了每个拼图,并使用它自己的主类来测试并确保拼图正常工作,当我尝试将拼图的代码添加到影片剪辑类时,我遇到了许多错误

输出错误

  **Warning** The linkage identifier 'feedback2' was already 
   assigned to the symbol 'wrong_box', and cannot be assigned 
    to the symbol 'graphics/scrambleAssets/wrong_box',
    since linkage identifiers must be unique.

和编译器错误

                  Line 132 1136: Incorrect number of arguments.  Expected 1.

第 132 行是这样的:

  if(ques_num==words.length){removeChild(checker);
  f3=new feedback3;
  addChild(f3);
   f3.x=100;
   f3.y=100;
  }else{
  getword();}

主类

      public function show_level1Puzzle(){

        level1Puzzle_screen = new level1Puzzle(this);
        remove_levelChooseBoy();

        addChild(levelPuzzleBoy_screen);
        level1Puzzle_screen.x=510;
        level1Puzzle_screen.y=380;
    }

** level1Puzzle 的类**

    package actions {

import flash.display.MovieClip;

public class level1Puzzle extends MovieClip {
                    public var main_class:Engine;

                    // variables used in puzzle
                   var words:Array = new Array; 
        Var rand1:int;var rand2:int; 
        var i:int; //variable used for loop iterations
        // more variables

    public function level1Puzzle(passed_class:Engine) {
                    main_class = passed_class;

    public function getword(passed_class:Engine) {
        main_class = passed_class;
        words=["cat","dog"];
        current_word=words[ques_num];
        setTiles(current_word.length);
        ques_num++;
    }
    public function setTiles(a) {tileArray=[ ];
        for(i=0;i<a;i++){
            var tempclip:Tile =new Tile;addChild(tempclip);
                tempclip.x=300+(i*180);tempclip.y=200;tempclip.tag=i;
            tempclip.original_posx=tempclip.x;
            tempclip.original_posy=tempclip.y;
            tileArray[i]=tempclip;

            var tempclip2:Placeholder =new Placeholder;addChild(tempclip2);
            tempclip2.x=300+(i*180);tempclip2.y=400;
            targetArray[i]=tempclip2;

        }//for i
        scramble_word(a);
    }

//更多解谜功能

【问题讨论】:

    标签: actionscript-3 flash oop inheritance functional-programming


    【解决方案1】:

    这个函数有一个参数:

    public function getword(passed_class:Engine) {
            main_class = passed_class;
            words=["cat","dog"];
            current_word=words[ques_num];
            setTiles(current_word.length);
            ques_num++;
        }
    

    在第 132 行,您没有传递参数,因此这就是错误消息的原因。

    【讨论】:

    • 正确,我应该更好地解释参数“checker”与按钮相关,我已在引擎类中声明它 var checker=new button_chk; leve1Puzzle_screen.addChildAt(checker,1);但它抛出了一个未定义的属性错误......如果我在 level1Puzzle 类中声明它,我会得到相同的未定义属性错误
    • 第 132 1136 行:参数数量不正确。预期 1. - 我的回答解决了这个问题。这是一个问答论坛,不是通过问题论坛调试您的代码问题。如果有新问题,请针对该特定问题提出新问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-25
    • 2018-05-21
    相关资源
    最近更新 更多