Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function communication between two classes 1

Status
Not open for further replies.

iranor

Programmer
Jun 17, 2004
174
CA
Hi. I'm trying to do some sort of socket connection, using VB (fscommand). My project is simple: I have 3 frames, and 2 classes.

One is called Connection, the other DataProcessor. Connection will handle connecting, sending packets, receiving them, disconnecting. DataProcessor has one function, ProcessData(sPacket) that scans the packet and determine what it is supposed to do. In the main frame, I have

var myConnect:Connection = new Connection();

I'm new to flash. All functions are public. Let's say ProcessData received a packet saying Welcome, it will send it to the Connection class, function ReceiveWelcome. I can't however manage to make them 'contact'. In the ProcessData function, I tried calling it with: ReceiveWelcome(), myConnect.ReceiveWelcome(), and Connection.ReceiveWelcome().

My function ReceiveWelcome is calling another function in the same class, and set some variables defined on top of it. ReceiveWelcome() isn't working, myConnect.ReceiveWelcome() either. Connexion.ReceiveWelcome() gives me an error saying something like 'Reference element doesn't have static attribute'. When I add the static thing, it doesn't execute my function :/...

So: How can I make two functions from different class communicate (and those functions calling other functions in the same class), or does someone has a good class documentation somewhere?

Thanks in advance.
 
If all the functions are public you should be able to communicate between the different classes, however it looks like you are using the main timline in flash to define the application state (ie each frame).

What I do is import my classes and instantiate them on the first frame, and have another separate 'GUI' class to handle the display of each application state. Thus, everything takes place on one frame.

your other problem - static functions are functions called on the class, not an instance of a class, so u need to use the name of the class rather than the name of the instance.

For example:
import com.app.MyClass;

and if your function inside your class is
public static blah():Void {
}

you would go Myclass.blah();

otherwise if its not static then you would go

var myInstance:MyClass = new MyClass();
myInstance.blah();



hope this helps
cheers,
J
 
Thanks for your post, classes are already more clear to me :)

I'll use static functions after all, I keep getting "Method 'myConnect' doesn't exist (when I call myConnect.ReceiveWelcome() in the DataProcessor class, but on the main frame I can type that).

Another thing: my flash app is in a VB form. It is supposed to send me the variable PACKET. My function that checks if PACKET have changed, can I put it in the DataProcessor class? I tried and, it doesn't gives me the packet content. (Flash requires me to put a var PACKET; in the beginning of the class, it's the problem isn't it?

It's just to make my code a bit clearer, but if I need to let the looping function on the main frame i'll do ^^
 
Another small problem :s
Code:
class Connection
{
    private var ConnectId:Number;
    private var ConnectTimeout:Number;
    private var IsConnecting:Number;        
    ...
    public static function Reconnect()
    {
        ConnectTimeout = 0;
        IsConnecting = 1;
        _root.getPacket();
        fscommand("null", "Connect");
        ConnectId = setInterval(WaitingConnexion, 100);
    }
}

Whenever I call Connection.Reconnect(), I get from the compiler 'Impossible to reach occurrence variables in static functions' (line 30: ConnectId = setInterval...)

I tried to put the ConnectId line in a separate function, but it keeps shooting me this error.

(On my main frame, I call myConnect:Connection = new Connection(), I don't know if it makes a difference ^^)
 
You can't access instance vars from static functions. Either make your function non-static by removing "static" from the function, or make your vars static by adding "static" to vars.

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top