Skip to main content
Inspiring
November 15, 2006
Question

external actionscripts question

  • November 15, 2006
  • 3 replies
  • 398 views
How do I change and combine the following .as file and .fla file into a single .fla....i've tried various ways but none of them seem to work....any help will be appriciated.


I have a listbox movie clip with an instance name of people_lb in the .fla and the movie clips name is SimpleChat as well as this code.

// a random username
var username = "user_" + getTimer();

// simplechat is a MovieClip on stage and is linked to the SimpleChat class
simplechat.connect("rtmp:/simplechat", username);


/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////


The following code is the external action script(.as).....

import mx.utils.Delegate;
import mx.controls.List;

class SimpleChat extends MovieClip
{

private var people_lb:List;

public var _username:String; // passed in to the connect method

private var _nc:NetConnection;
private var _chatSO:SharedObject;





// sets up the NetConnection
public function connect( rtmpString:String, username:String )
{

// let's save a reference to the username
_username = username;

_nc = new NetConnection();
_nc.owner = this;
_nc.onStatus = function ( info )
{
//trace(info.code);
if(info.code == "NetConnection.Connect.Success")
{
trace("connected successfully");
// now we can hook up the SharedObject
this.owner.connectSO( this );
}
}

// let's connect
_nc.connect(rtmpString, _username);

}

private function connectSO( nc )
{
// get a reference to a non-persistent remote SharedObject called 'chat_so'
_chatSO = SharedObject.getRemote("chat_so", nc.uri, false);

// Delegate the SharedObject onSync to onChatSOSync
_chatSO.onSync = Delegate.create(this, onChatSOSync);


// connect the SharedObject - often gets forgotten but rather important 😉
_chatSO.connect( nc );

}

private function onChatSOSync ( list )
{
// clear the peoplelist
people_lb.removeAll();

// iterate over all the data 'slots' in the SharedObject
for (var i in _chatSO.data)
{
if (_chatSO.data != null)
{
// this is the client object as stored by the server within application.onConnect
var clientObj = _chatSO.data
;
// add each user
people_lb.addItem({label:clientObj.username, data:clientObj});
}
}
};

} // class ends
    This topic has been closed for replies.

    3 replies

    Inspiring
    November 15, 2006
    well if thats your attitude then i'd rather get help from a friendly people....sorry for rubbing your ribs the wrong way
    November 15, 2006
    Did you create the SO's on the server side?

    Incidentally, comments like this:

    " nope all you did was create errors"

    are a sure fire way to get me to ignore your posts. My mistake for trying to help you in the first place. No matter though... you won't be troubled by me responding to your posts in the future.
    November 15, 2006
    Well... one way would be to create a movie clip with a list in it (named people_lb), and then add the following to the first frame


    import mx.utils.Delegate;

    var _username:String; // passed in to the connect method

    var _nc:NetConnection;
    var _chatSO:SharedObject;

    function connect( rtmpString:String, username:String )
    {

    // let's save a reference to the username
    _username = username;

    _nc = new NetConnection();
    _nc.owner = this;
    _nc.onStatus = function ( info )
    {
    //trace(info.code);
    if(info.code == "NetConnection.Connect.Success")
    {
    trace("connected successfully");
    // now we can hook up the SharedObject
    this.owner.connectSO( this );
    }
    }

    // let's connect
    _nc.connect(rtmpString, _username);

    }

    function connectSO( nc )
    {
    // get a reference to a non-persistent remote SharedObject called 'chat_so'
    _chatSO = SharedObject.getRemote("chat_so", nc.uri, false);

    // Delegate the SharedObject onSync to onChatSOSync
    _chatSO.onSync = Delegate.create(this, onChatSOSync);


    // connect the SharedObject - often gets forgotten but rather important ;-)
    _chatSO.connect( nc );

    }

    function onChatSOSync ( list )
    {
    // clear the peoplelist
    people_lb.removeAll();

    // iterate over all the data 'slots' in the SharedObject
    for (var i in _chatSO.data)
    {
    if (_chatSO.data != null)
    {
    // this is the client object as stored by the server within application.onConnect
    var clientObj = _chatSO.data;
    // add each user
    people_lb.addItem({label:clientObj.username, data:clientObj});
    }
    }
    };


    Drag an instance out on to the stage, and name it simplechat.
    Inspiring
    November 15, 2006
    nope all you did was create errors and even if i fix the errors and add username = "bob";......alls i get is a blank list box.