AS3 / Flex 4 Datagroup Custom Itemrenderer Video对象

时间:2011-09-13 03:54:33

标签: flex actionscript-3 flex4

我有一个带有自定义视频的数据组&音频流itemRenderer和用户的dataProvider。顺便说一句,该项目是一个视频会议应用程序。这是我的问题:

列表中有2个用户,w / c是dataGroup的dataProvider。

array[0] = user1;
array[1] = user2;

当user1退出房间时,user2将发生user1的位置。所以它会变成这样:

array[0] = user2;

问题是,array [0]中的itemrenderer会停留,而array [1]的itemrenderer将会消失。所以,就像user2是那个已经离开房间而不是用户1的人。

我通过刷新/更新/更新列表来修复问题,以便刷新itemrenderer,这是我的代码:

private function restoreCameras():void{
    //backup the current itemrenderer
            _stored_itemrenderer = dgUsers.itemRenderer;
    //nullify all the contents of the dataGroup
            dgUsers.dataProvider = null;
            dgUsers.itemRenderer = null;
    //restore the dataGroup's dataProvider, for refreshing the data
            dgUsers.dataProvider = userArrayList;
    //restore the itemrenderer backup
            dgUsers.itemRenderer = _stored_itemrenderer;
}

我的做法好吗?我也使用此功能来刷新相机输入(w / c是itemrenderer)。但是当刷新它时,音频/视频源堆栈。有什么建议吗?

谢谢, 吉尔伯特


这里是数据组:

<s:DataGroup id="dgUsers"
width="320" top="155" itemRenderer="com.classroom.videoconference.videoRenderer"> <s:layout> <s:TileLayout horizontalGap="1" orientation="rows"/> </s:layout> </s:DataGroup>


这是Custom ItemRenderer:

<fx:Script>
    <![CDATA[
        import mx.events.CloseEvent;
        import spark.components.DataGroup;

        private function closeVideopod(e:CloseEvent):void{
            var parentDG:DataGroup = owner as DataGroup;
            parentDG.dataProvider.removeItemAt(parentDG.dataProvider.getItemIndex(data));
            //(parentDG.dataProvider as ArrayCollection).refresh();
            this.removeChild(vidpod);
            vidpod.removeAllElements();
        }

    ]]>
</fx:Script>
<s:states>
    <s:State name="normal"/>
    <s:State name="hovered"/>
</s:states>

<s:layout>
    <s:TileLayout/>
</s:layout> 
<videoconference:Videopod id="vidpod" width="151" height="143" userItem="{data}" toolTip="{data.name}" close="closeVideopod(event)"/>

这是DataProvider:

 var userObj:Object = userListSO.data.testArr;
var userArray:Array = userObj.Name;
var rolesArray:Array = userObj.Role;
var statusArray:Array = userObj.Status;
var userRenderAC:ArrayCollection = new ArrayCollection();

for(var x:int = 0; x < userArray.length; x++){
    userRenderAC.addItem({
        name: userArray[x],
        role: rolesArray[x],
        status: statusArray[x]
    });

}

this.userArrayList = userRenderAC;
   dgUsers.dataProvider = this.userArrayList;


这是退出处理程序:

private function alertExitHandler(e:CloseEvent):void{
            if(e.detail == Alert.YES){
                var userObj:Object = new Object();

                var obj:Object = userListSO.data.testArr;
                var userList:Array = obj.Name;
                var rolesArray:Array = obj.Role;
                var statusArray:Array = obj.Status;

                var updatedUserList:Array = new Array();
                var updatedRolesList:Array = new Array();
                var updatedStatusList:Array = new Array();


                for(var ctr:int = 0; ctr < userList.length; ctr++) {
                    var sessionName:String = userDetails.username;
                    var listName:String = userList[ctr];

                    if(listName != sessionName) {
                        updatedUserList.push(listName);
                        updatedRolesList.push(rolesArray[ctr]);
                        updatedStatusList.push(statusArray[ctr]);
                    }
                }

                userObj.Name = updatedUserList;
                userObj.Role = updatedRolesList;
                userObj.Status = updatedStatusList;
                //here is the updated propery testarr...
                userListSO.setProperty("testArr", userObj);

                setTimeout(logout,500);
            }else{
                //logout();
            }

        }

0 个答案:

没有答案