Reputation: 99
I want a way to pass a string statement from one base class to an other.
The two classes are CLICK and READ. What's an easy way to do this? I haven't
worked in classes that often to know some of the simple tricks. I appreaciate your help.
Thanks,
Class: CLICK
Base Class: ClickClass
Object I've turned in to a base class and placed in the same FLA
package {
import flash.events.Event;
import flash.display.MovieClip;
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.display.*;
public class ClickClass extends MovieClip {
//public var read:String = "It's Done!";
public function ClickClass() {
b.addEventListener(MouseEvent.CLICK, onClick);
}
public function onClick(event:MouseEvent){
trace("test!");
//t.text = String(read);
//ReadClass.t.text = String(read);
}
}
}
Class: READ
Base Class: ReadClass
Object I've turned in to a base class and placed in the same FLA
package {
import flash.events.Event;
import flash.display.MovieClip;
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.display.*;
public class ReadClass extends MovieClip {
public var read:String = "It's Done!";
public function ReadClass() {
//t.text = String(read);
/*
1119: Access of possibly undefined property
read through a reference with static type Class.
*/
}
//public functions
}
}
ERRORS: 'talk to a DynamicTextField in an other class'
1119: Access of possibly undefined property read through a reference with static type Class.
1120: Access of undefined property read.'previous error'
ERROR: 'Attaching scripts to document class'
5006: An ActionScript file can not have more than one externally visible definition
Upvotes: 0
Views: 542
Reputation: 9572
In the third class example, DONE is a static constant so , after importing the UISTrings class you can call it from any other class like this
t.text = UIStrings.DONE;
I agree with klickverbot that it would be a cleaner solution.
Upvotes: 0
Reputation: 6130
I am not quite sure if I completely got your question, but you could of course make »read« a static
member of ClickClass
(probably a const
) and access it via ReadClass.read
…
A cleaner solution would probably be to create a third class, maybe called UiStrings
which enumerates all the strings needed in the user interface:
public class UiStrings {
public static const DONE :String = "It's done";
}
Upvotes: 2