如何在连接到服务器之前访问 swf 加载 url 参数 - red5、flex
我是 Flex 新手,所以我希望能有一些简单的解释。不管怎样,我试图从加载 swf 文件的 url 获取参数。一切都好,它可以工作。
var room_id:Number = root.loaderInfo.parameters.room_id;
当我在连接到 red5 服务器之前尝试执行此操作时,会出现问题。现在我想从 url 中获取 id,以了解我应该在哪个房间建立连接,但是如果在建立连接之前当我尝试访问此参数时 Flex 给出错误,我该怎么做呢?
错误#1009:无法访问空对象引用的属性或方法。
目前有我的代码。
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;
}
如果我取消注释行“var room:Number = vars("room");”我收到错误,如果我稍后在函数“onConnected”中使用此行,则没有问题,我可以访问通过 url 传递的所有参数。 现在可以在连接之前获取这些参数吗?我该怎么办?网站本身在 php 上运行,所以基本上我试图将 php 参数传递给 swf 对象。 我将非常感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
另一个问题我自己回答。无论如何,这只是一个愚蠢的错误。要访问
loaderInfo
属性,必须完全下载所有 swf。因此,当我将第一个函数从creationComplete
触发到applicationComplete
时,我只是更改了事件,仅此而已。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 fromcreationComplete
toapplicationComplete
and thats it.