views:

35

answers:

2

Hi, 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

+2  A: 

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";
}
klickverbot
@klickverbot, markup for good explanation. I've been using classes to clean up my coding skills. I'm not getting it yet, but I would like to understand how a third class would work, or the 'dirty solution'.
pixelGreaser
A: 

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.

PatrickS