AS3 - Error 1119: access to a possible property undefined propertyListList through a link with a class of static type.

I need to access a variable from another class, and I continue to get the error "1119: access to a possible property undefined propertyListList via a link with a static class type". I do not see what I am doing wrong, since my variable is made "public" and "static".

where the variable is executed.

package classes.enemy { imports ... public class Enemy extends MovieClip { public static var enemyList:Array = new Array(); ** var speed:Number; public function initialize() { var stageReff:Stage = this.stage as Stage; addEventListener("enterFrame", enterFrame); } public function Enemy() { enemyList.push(this); ** this.x = 700; this.y = Math.random()*200 + 50; speed = Math.random()*5 + 5; } //code } } 

who needs access to a variable

 package classes.ship { imports ... public class Bullet extends MovieClip { var speed:Number; public function initialize() { var stageReff:Stage = this.stage as Stage; stage.addEventListener("enterFrame", enterFrame); } //code function enterFrame(e:Event):void { this.x += speed; trace(enemy.enemyList); ** } } } 

Put "**" in the lines where the problem occurs and where the variable is produced, just to make it understandable.

Classes are in different folders (classes> enemy and classes> ship), I don’t know if this has anything to do with it.

Thanks in advance.

+4
source share
4 answers

If you want to access a static property, you need to use the class that it is defined in: Enemy.enemyList

Also make sure the class is imported correctly in your ship class: import classes.enemy.Enemy;

+1
source

I ran into the same problem and solution:

your class name is "enemy" and when you access it, it remains as a class, not an object

try to create an object of your class

 enemy1 = new enemy(); // in your bullet class 

or if the bullet is a movie clip in which the enemy is like its child movie clip, then change its instance name to enemy1 so that you can access it as an object of your defination class β€œenemy”

+2
source

I had the same problem with error 1119 on as3.

I took off my hair and then noticed that a message appeared related to the TLF text.

So, I switched to the action of the script settings in the FLA file and integrated the textlayout library into the code.

Hope this helps.

+1
source

Update 1:

Remember to also import your Enemy class.

I believe that Enemy in Bullet is an instance of a class, so you cannot call a static property from an instance that you need to call with the name of the class where it is declared:

so Bullet Enemy should have Enemy

 package classes.ship { //... import enemy.Enemy; //... function enterFrame(e:Event):void { this.x += speed; trace(Enemy.enemyList); ** } 
0
source

Source: https://habr.com/ru/post/1388867/


All Articles