Search code examples
phpapache-flexred5url-parameters

how to acceess swf loading url params, before connecting to the server - red5, flex


I'm new to the flex, so i hope there will be some simple explanation. Anyway, im trying to get parameters from url, which load swf file. its all ok, it works.

var room_id:Number = root.loaderInfo.parameters.room_id;

Problem occurs when im trying to do this, before i making connection to red5 server. Now i want to take id from url, to get known in to which room i should make a connection, but how can i do this, if flex gives me an error when i trying to access this parameter before im establishing connection.

Error #1009: Cannot access a property or method of a null object reference.

There is my code at the moment.

protected function application1_creationCompleteHandler(event:FlexEvent):void {
    //var room:Number = vars("room");
    connection = new NetConnection();
    connection.connect("rtmp://127.0.0.1/video");
    connection.addEventListener(NetStatusEvent.NET_STATUS, onConnected);
    connection.client = this;
}
private function vars(id:String) : Number {
    var newID:Number
    switch(id) {
        case "room" :
        newID = root.loaderInfo.parameters.room_id;
        break;
    }
    return newID;
}

If i uncomment the line "var room:Number = vars("room");" i get error, if i using this line later in function "onConnected", there is no problems, i can access all parameters passed via url. Now is it possible to get those parameters before connection, what should i do? Website by itself runs on php, so basically im trying to pass php params to swf object. I would be very grateful.


Solution

  • Another question im answering by myself. Anyway, there was just a stupid mistake. To access loaderInfo properties, all swf must be completely downloaded. So i just changed event when i fired first function from creationComplete to applicationComplete and thats it.