开发者

AS3 Error 1000 on Vector

So I've never worked with Vectors in Flash before and I wanted to write a little test application with a Vector using a custom object. But I'm getting: error 1000: Ambiguous reference to Vector when I try launching the application. I can't figure out for the life of me what's wrong. I tried not using a custom object and just instantiating a string Vector from an online tutorial and I'm getting the same thing.

Here's what I got:

package
{
import TestPlayer; // The custom player class
import flash.display.MovieClip;

public class Vector extends MovieClip
{
    private var array:Array = new Array();
    private var vector:Vector.<TestPlayer>;

    public function Vector()
    {
        array[0] = [0, 0, "Bob", false];
        array[1] = [1, 0, "Frank", true开发者_Go百科];
        array[2] = [2, 1, "Sarah", true];
        Load();
    }

    private function Load():void
    {
        var aPlayer:Player = null;
        vector = new Vector.<TestPlayer>();

        try
        {
            var numRows:int = array.length;

            for (var i = 0; i < numRows; i++)
            {
                aPlayer = new Player();

                aPlayer.playerID = array[i][0];
                aPlayer.playerName = array[i][1];
                aPlayer.playerTypeID = array[i][2];
                aPlayer.hasProgress = array[i][3];

                vector.push(aPlayer);
            }
        }
        catch (error:Error) { }
    }
}

The custom player class looks like this:

package
{
    public class TestPlayer
    {
        private var _playerID:int;
        private var _playerName:String = "";

        public function get playerID():int 
        {
            return _playerID;
        }

        public function set playerID(value:int):void 
        {
            _playerID = value;
        }

        public function get playerName():String 
        {
            return _playerName;
        }

        public function set playerName(value:String):void 
        {
            _playerName = value;
        }
            [...]
    }
}

I don't know if it matters, but I'm working in Flash CS5, and I have a blank FLA that imports the class. No other errors so far. Hope you can help. Let me know if you need anymore info, thanks.


The ambiguous reference is because you've got a naming collision. The class you've written is named "Vector", which it can't distinguish from the top-level class Vector. The fix is simple, avoid naming your classes the same as a pre-existing class.

If both classes belong to separate namespaces, you can reuse class names, as long as you use thier fully-qualified name whenever you call the class.

Assume you have a class:

package foo.bar
{
  class MovieClip
  ...
}

You could instantiate both types of MovieClips as follows:

flashMovieClip = new flash.display.MovieClip();
myMovieClip = new foo.bar.MovieClip();

Unfortunately, both your Vector and the flash Vector exist in the top-level namespace, so (AFAIK) there's no way of removing the ambiguity without renaming your class. For simplicity sake, avoid naming collisions and you should be golden.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜