Skip to main content
Known Participant
Mar 18, 2010 12:29 PM UTC
Question

how to call a method in another class ?

how can i use getUserID method in my main.as  ??

NetConnectionClient.as

package com {

import flash.events.EventDispatcher;

import flash.events.Event;

public class NetConnectionClient extends EventDispatcher {
    

     public static const ONUSERID:String = "onUserID";

     private var _uID :Number;

  

     public function setUserID(uID:Number):void {

         _uID : uID;

        dispatchEvent(new Event(NetConnectionClient.ONUSERID));

     }

 

     public function getUserID():Number {
        return _uID;
     }

   }

}

Thanks!

    This topic is closed to new replies. Start a new post to keep the conversation going.

    6 replies

    Mar 18, 2010 12:38 PM UTC

    That depends... do you have a reference to the NetConnectionClient in your main.as? If so, you should be able to just listen for the event dispatch, or just invoke the getUserId mehod from main.as. Are those not working for you?

    Might be helpful if you post the relevant code from your main.as, or explain the classes that stand between main.as and your NetConnectionClient instance

    Translate
    tkosenAuthor
    Known Participant
    Mar 18, 2010 1:00 PM UTC

    package{
    import com.NetConnectionClient;
    import com.NetConnectionClientEvent;
    import com.NetConnectionManager;

    import fl.data.DataProvider;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.NetStatusEvent;
    import flash.events.SecurityErrorEvent;
    import flash.events.SyncEvent;
    import flash.net.SharedObject;
    import fl.data.DataProvider;
    import fl.video.FLVPlayback;
    import flash.display.MovieClip;


    public class MainAdm extends Sprite{
     
      private var nc:NetConnectionManager;
      private var so:SharedObject;
      private var soEl:SharedObject;
      private var selectedUser:Number = 0;
      private var userID:String;
     
      public function MainAdm(){
       nc=new NetConnectionManager();
       nc.addEventListener("onConnect",onConnect);
       nc.client = new NetConnectionClient();
       nc.client.addEventListener("onUserID",onUserId);
       nc.client.addEventListener("onReceiveChatMsg",onReceiveChatMsg);
       nc.client.addEventListener("onElKaldirMsg",onElKaldirMsg);
       nc.client.addEventListener("ongetUserID",ongetUserID);

         i want to trace it here   

         trace(?????.getUserID().toString());

      


       sendButton.label = "Send Message";
       sendButton.addEventListener(MouseEvent.CLICK,onSendButtonClicked);
      
       deselectButton.label = "clear";
       deselectButton.addEventListener(MouseEvent.CLICK,onDeselectButtonClicked);
      
       /*chatInputText.addEventListener(Event.CHANGE,onEnterPressed);*/
      
       usersList.addEventListener(Event.CHANGE,onUserSelected);  
       /*sendButton.enabled =
       chatInputText.enabled = false;*/
      
       elKaldir.label = "El Kaldir";
       elKaldir.addEventListener(MouseEvent.CLICK,onElKaldir);
      
       /*usersTList.columnWidth = 100;
       usersTList.rowHeight = 100;
       usersTList.columnCount = 1;
       usersTList.rowCount = 2;
       usersTList.move(30, 250);*/
     
       nc.createNetConnection("rtmp://localhost/FMSTutorial22");

    }

    .

    .

    .

    .

    }

    }

    Translate
    Mar 18, 2010 4:08 PM UTC

    I'd need to see your NetConnectionClient class to know for sure that this would work.... but what I'd do is define the NetConnectionClient so it's a member of the main.as. That would make it easier to reference.

    public class MainAdm extends Sprite{
     
      private var nc:NetConnectionManager;
      private var so:SharedObject;
      private var soEl:SharedObject;
      private var selectedUser:Number = 0;
      private var userID:String;

    public var ncc:NetConnectionClient;
     
      public function MainAdm(){
       nc=new NetConnectionManager();
       nc.addEventListener("onConnect",onConnect);

    ncc = new NetConnectionClient();
       nc.client = ncc
       ncc.addEventListener("onUserID",onUserId);
        ncc.addEventListener("onReceiveChatMsg",onReceiveChatMsg);
        ncc.addEventListener("onElKaldirMsg",onElKaldirMsg);
        ncc.addEventListener("ongetUserID",ongetUserID);

         i want to trace it here  

         trace(ncc.getUserID().toString());

    }

    }

    Translate