🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.pl.programy.flash-5
Article #33962

[AS|2.0] Proste klasy .. czemu?

#33962
From: MANi
Date: Mon, 05 Mar 2007 23:33
73 lines
2226 bytes
Witam Serdecznie!

    Napisalem 2 proste klasy, ktore znajduja sie ponizej, ale podczas 
kompilacji wyskakuje taki error:
------------------
A class's instance variables may only be initialized to compile-time 
constant expressions.

      	public var weapon:Item = new Item();
------------------

    Potrafie sie pozbyc tego bledu w momencie, gdy nie uzyje konstruktora:
------------------
public var weapon:Item;
------------------

    Czy ktos potrafi mi wytlumaczyc dlaczego tak sie dzieje? Co 
zmodyfikowac, aby jednak moc korzystac z konstruktora "Item()"?



### AS|2.0

Item.as
---------
class Item {
	private var _itemName:String = null;
	
	function Item() {
		this._itemName = "---";
	}
	public function get itemName():String {
		return this._itemName;
	}	
	public function set itemName(s_itemName:String):Void {
		this._itemName = s_itemName;
	}		
}


Set.as
---------
import Item;
class Set {
	public var weapon:Item = new Item();
	private var _gName:String = null;

	function Set(s_gName:String) {
		this._gName = s_gName;
	}	
	public function get gName():String {
		return this._gName;
	}	
	public function set gName(s_gName:String):Void {
		this._gName = s_gName;
	}		
}	


Main.fla
---------
import Item;
import Set;

var mySet:Set = new Set("qwerty");
mySet.weapon.itemName = "kosa";
trace(mySet.weapon.itemName);


-- 
Pozdrawiam, MANi aka Vagabundo
______________________________
G G  ::::::::  0 x 3 6 A 0 0 D
Technical Details
Message-ID: <esi9c4$5ou$1@ns.netstone.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.dialog.net.pl!news.master.pl!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.dialog.net.pl!news.master.pl!not-for-mail
From: MANi <mani@fuck.off.spamerze.master.pl>
Newsgroups: alt.pl.programy.flash-5
Subject: [AS|2.0] Proste klasy .. czemu?
Date: Tue, 06 Mar 2007 00:33:31 +0100
Organization: MasterNET
Lines: 73
Message-ID: <esi9c4$5ou$1@ns.netstone.pl>
NNTP-Posting-Host: ns.master.pl
Mime-Version: 1.0
X-Trace: news.dialog.net.pl 1173138309 28884 89.151.0.5 (5 Mar 2007 23:45:09 GMT)
X-Complaints-To: abuse@dialog.net.pl
NNTP-Posting-Date: Mon, 5 Mar 2007 23:45:09 +0000 (UTC)
User-Agent: Thunderbird 1.5.0.10 (Windows/20070221)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit