Skip to main content
Known Participant
March 18, 2010
Question

how to call a method in another class ?

  • March 18, 2010
  • 1 reply
  • 1124 views

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 has been closed for replies.

    1 reply

    March 18, 2010

    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

    tkosenAuthor
    Known Participant
    March 18, 2010

    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");

    }

    .

    .

    .

    .

    }

    }

    March 18, 2010

    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());

    }

    }