A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Getting XML children

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    4

    Getting XML children

    Hello, everyone.

    I'm having a bit of a problem.

    There's this video chat application which I need to modify, and I'm really at a loss.

    There's an XML which tells you the number of users logged on. This XML is then fed to a ScrollPane. Now, I need to get this number and feed it into a PHP.

    All's fine and dandy, but when I use myXML.list.length(); it throws undefined.

    The XML structure is XML > List > Viewers.


    Here's the script:

    Code:
    import flash.external.ExternalInterface;
    
    
    var transLang="off";
    var mp3:Sound;
    var mp3Control: SoundChannel = new SoundChannel();
    var originalViewSize="big";
    var chatIsAllowed;
    var rand=0;
    var userlistnumber;
    
    
    userlistnumber = userlistXML.children().length();
    
    
    
    chatText.sPane.x = -5.3;
    chatText.sPane.y = -3.95;
    chatText.sPane.width = 397.75;
    chatText.sPane.height = 398.6;
    
    
    if (themeXML.@musicPlayer!="true") {
    	meniul.musicPlayerComponent.visible=false;
    }
    if ((themeXML.@w2w!="true")||(paramList.sessionType!="private" )) {
    	myCameraComponent.visible=false;
    }
    
    function sendUserStatus(event:Event)
    {
    	// We will use URLRequest to post our variables to a
    	// PHP file which will return variables back
    
    	// Set the location of your PHP file
    	var urlReq:URLRequest = new URLRequest("http://thenaughtyandthenice.east-wolf.com/assets/swf/userlist.php");
    
    	// Set the method to POST
    	urlReq.method = URLRequestMethod.POST;
    
    	// Define the variables to post  
    	// Here is where our username and password variables are set
    	// For more variables we would add additional parameters to our urlVars variable
    	var urlVars:URLVariables = new URLVariables();
    	urlVars.userlist = userlistnumber;
    
    	// Add the variables to the URLRequest;
    	urlReq.data = urlVars;
    
    	// Add the URLRequest data to a new Loader
    	var loader:URLLoader = new URLLoader(urlReq);
    
    	// Set the loader format to variables and post to the PHP
    	loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    	loader.load(urlReq);
    }
    
    this.addEventListener(Event.ENTER_FRAME,sendUserStatus);
    
    
    var userlistXML:XML;
    function loadList() {
    	rand =Math.round(Math.random()*1000);
    	var linkul:String = paramList.sitePath+"userListFull.php?performer="+paramList.performerId+"&random="+rand+"&userId="+paramList.performerId+"&pasword="+paramList.pasword;
    	if (paramList.testing){
    		loadXML(paramList.sitePath+"userList.php", userlistXML, onListLoaded );
    	}else{
    		loadXML(linkul, userlistXML, onListLoaded );
    	}
    }
    var oldListNumber:int=0;
    function onListLoaded( e:Event ) {
    	userlistXML=new XML(e.target.data);	
    	var lH : ListHolder =  new ListHolder();
    	listScrollPane.source=lH;
    	lH.loadList();
    }
    
    var updateListInterval:uint=setInterval(loadList,500);
    
    
    //var chatSO=SharedObject.getRemote(paramList.performerId+"chat",nc.uri,false);
    //chatSO.connect(nc);
    //chatSO.client=this;
    
    
    var msgBuf:Array=new Array();
    var curentIndex:int=0;
    function getMsg(nick, msg, userId, color) {
    	var nickColor=color;
    	
    	var o:Object={nick:nick,msg:msg,nickColor:nickColor,messageColor:MovieClip(root).themeXML.@chatTextColor,userId:userId};
    	msgBuf.push(o);
    }
    
    
    var addToChatInt:uint=setInterval(addToChat,300);
    function addToChat(){
    	if (msgBuf.length>curentIndex){	
    		chatText.addChatLine(msgBuf[curentIndex].nick,msgBuf[curentIndex].msg,msgBuf[curentIndex].nickColor,msgBuf[curentIndex].messageColor,msgBuf[curentIndex].userId);
    		fChat.chatText.addChatLine(msgBuf[curentIndex].nick,msgBuf[curentIndex].msg,msgBuf[curentIndex].nickColor,"0xFFFFFF",msgBuf[curentIndex].userId);
    		var beep:Sound = new Alerta();
    		if (meniul.chatSoundsBox.selected) {
    			beep.play();
    		}
    		curentIndex++;
    	}
    }
    
    
    function play_song(song_path, song_title) {
    	mp3Control.stop();
    	if (song_path!=null) {
    		mp3=new Sound(new URLRequest(song_path));
    		mp3Control=mp3.play();
    		meniul.musicPlayerComponent.songText.text=song_title;
    		meniul.musicPlayerComponent.songText.setTextFormat(staticFormat);
    	} else {
    		meniul.musicPlayerComponent.songText.text=translationXML.@noSongPlaying;
    		meniul.musicPlayerComponent.songText.setTextFormat(staticFormat);
    	}
    	meniul.musicPlayerComponent.volumeSet(null);
    }
    
    
    if (themeXML.@musicPlayer=="true") {
    	nc.call('ask_song',null);
    }
    function send_song(song_path, secs, song_title) {
    	mp3Control.stop();
    	if (song_path!=null) {
    		mp3=new Sound(new URLRequest(song_path));
    		mp3Control=mp3.play(secs);
    		meniul.musicPlayerComponent.songText.text=song_title;
    		meniul.musicPlayerComponent.songText.setTextFormat(staticFormat);
    	} else {
    		meniul.musicPlayerComponent.songText.text=translationXML.@noSongPlaying;
    		meniul.musicPlayerComponent.songText.setTextFormat(staticFormat);
    	}
    	meniul.musicPlayerComponent.volumeSet(null);
    }
    
    
    meniul.volSymb.barVolume.addEventListener( Event.CHANGE, volumeSet );
    var transforms:SoundTransform;
    function volumeSet( e:Event ) {
    	try {
    		transforms=new SoundTransform(meniul.volSymb.barVolume.value/100,0);
    		performersWebcam.performersWebcam.ns1.soundTransform=transforms;
    	} catch (e:Error) {
    	}
    }
    
    butGroup.gotoPrivateBtn.addEventListener(MouseEvent.CLICK, privateInvitation);
    function privateInvitation(e:Event){
    	nc.call('privateInvitation',null,paramList.userName, paramList.userId, paramList.chips);
    	butGroup.gotoPrivateBtn.visible=false;
    	var intervalShowBut:uint = setTimeout(showPrivateBut, 60000);
    }
    
    butGroup.bigScreenBtn.addEventListener(MouseEvent.CLICK, screenSize );
    var originalHeight=375;
    var originalWidth=performersWebcam.width;
    var originalWebcamBGHeight=CamBG.height;
    var originalWebcamBGWidth=CamBG.width;
    var originalChatInputY=chatInput.y;
    var originalChatTextY=chatText.y;
    var originalChatTextX=chatText.x
    var originalChatInputX=chatInput.x;
    var originalMyCameraComponentX=myCameraComponent.x;
    
    function screenSize(e:Event){
    	performersWebcam.scaleSymb.ratio=1;
    	performersWebcam.scaleSymb.setRatio();
    	performersWebcam.performersWebcam.nominalFun();
    	if (butGroup.bigScreenBtn.label==translationXML.@bigscreen){
    		// aici se face mare
    		butGroup.bigScreenBtn.label=translationXML.@normalscreen;
    		//CamBG.height=HEIGHT_DOUBLE;
    		//CamBG.width=performersWebcam.width+2*performersWebcam.x;
    		ChatBG.visible=false;
    		CamBG.gotoAndStop(2);
    		button_bar.gotoAndStop(2);
    		butGroup.bigScreenBtn.x = 0.5;
    		butGroup.bigScreenBtn.y = 46;
    		butGroup.bigScreenBtn.width = 153;
    		butGroup.bigScreenBtn.height = 32;
    		butGroup.exitBtn.x = 0.5;
    		butGroup.exitBtn.y = 84.55;
    		butGroup.exitBtn.width = 153;
    		butGroup.exitBtn.height = 32;
    		meniul.gotoAndStop(2);
    		meniul.chatSoundsBox.x = 453;
    		meniul.chatSoundsBox.y = 127.55;
    		chatText.chatBack.gotoAndStop(2);
    		chatInput.gotoAndStop(2);
    		ListBG.gotoAndStop(2);
    		right_pane.gotoAndStop(2);
    		chatText.sPane.x = 168.25;
    		chatText.sPane.y = -3.95;
    		chatText.sPane.width = 228.7;
    		chatText.sPane.height = 508.4;
    		performersWebcam.width = 563;
    		performersWebcam.height = 421;
    		//ControlsBG.visible=false;
    		myCameraComponent.x = performersWebcam.width-myCameraComponent.width;
    		viewSize="big";
    		
    		//chatInput.y=performersWebcam.height+performersWebcam.y-6;
    		//chatText.y=chatInput.y-chatInput.BG.height-chatText.height-3;
    		//chatInput.x=originalChatInputX-20;
    		//chatText.x=originalChatTextX-20;
    		ExternalInterface.call("large1()");
    	}else{
    		//aici se face normal
    		butGroup.bigScreenBtn.label=translationXML.@bigscreen;
    		//CamBG.height=originalWebcamBGHeight;
    		//CamBG.width=originalWebcamBGWidth;
    		//ControlsBG.visible=true;
    		ChatBG.visible=false;
    		CamBG.gotoAndStop(1);
    		button_bar.gotoAndStop(1);
    		butGroup.bigScreenBtn.x = 0.5;
    		butGroup.bigScreenBtn.y = -80;
    		butGroup.bigScreenBtn.width = 190;
    		butGroup.bigScreenBtn.height = 32;
    		butGroup.exitBtn.x = 197.55;
    		butGroup.exitBtn.y = -80;
    		butGroup.exitBtn.width = 190;
    		butGroup.exitBtn.height = 32;
    		meniul.gotoAndStop(1);
    		meniul.chatSoundsBox.x = 277.3;
    		meniul.chatSoundsBox.y = 28;
    		chatText.chatBack.gotoAndStop(1);
    		chatInput.gotoAndStop(1);
    		ListBG.gotoAndStop(1);
    		right_pane.gotoAndStop(1);
    		chatText.sPane.x = -5.3;
    		chatText.sPane.y = -3.95;
    		chatText.sPane.width = 397.75;
    		chatText.sPane.height = 398.6;
    		performersWebcam.width = 391.5;
    		performersWebcam.height = 292;
    		myCameraComponent.x=originalMyCameraComponentX;
    		viewSize="normal";	
    		ExternalInterface.call("small1()");
    	}
    	
    }
    
    butGroup.exitBtn.addEventListener(MouseEvent.CLICK, exitFun );
    function exitFun(e:Event){
    	connectionEstablished=false;
    	nc.close();
    	ExternalInterface.call("endShow", paramList.sessionType);
    }
    
    
    function showPrivateBut(){
    	if (paramList.sessionType!="private"){
    		butGroup.gotoPrivateBtn.visible=true;
    	}
    }
    
    function disconMes(type){
    	dontShowConClosed=true;
    	nc.close();
    	warn = new ErrorMessage();
    	mist.setVisible(true);
    	warn.x=WIDTH/2;
    	warn.y=HEIGHT/2;
    	this.addChild(warn);
    	var redirTimeOut:uint;
    	
    	switch (type){
    		case "kick":
    			warn.setTexts(translationXML.@warning, translationXML.@beenKicked,"index");
    			redirTimeOut=setTimeout(redirectTo,5000,paramList.redirectLink);
    			break;
    		case "ban":
    			warn.setTexts(translationXML.@warning, translationXML.@beenBanned,"index");
    			redirTimeOut=setTimeout(redirectTo,5000,paramList.redirectLink);
    			break;	
    		case "left":
    			warn.setTexts(translationXML.@warning, translationXML.@perfLeft,"index");	
    			redirTimeOut=setTimeout(redirectTo,5000,paramList.redirectLink);
    			break;
    		case "over":
    			if (paramList.sessionType=="public"){
    				warn.setTexts(translationXML.@warning, translationXML.@connOver,"index");			
    			}else{
    				warn.setTexts(translationXML.@warning, translationXML.@connOverLackOfChips,"index");		
    			}
    			redirTimeOut=setTimeout(redirectTo,5000,paramList.redirectLink);
    			break;
    		case "private":
    			this.removeChild(warn);
    			var warnC = new ChoiceMessage();
    			warnC.x=WIDTH/2;
    			warnC.y=HEIGHT/2;
    			this.addChild(warnC);
    			warnC.setTexts(translationXML.@choicePeekHeader, translationXML.@choicePeekBody, type);
    			break;
    		case "private_public":
    			this.removeChild(warn);
    			warnC = new ChoiceMessage();
    			warnC.x=WIDTH/2;
    			warnC.y=HEIGHT/2;
    			this.addChild(warnC);
    			warnC.setTexts(translationXML.@choiceNudeHeader, translationXML.@choiceNudekBody, type);			
    			break;
    		default:
    			warn.setTexts(translationXML.@warning, translationXML.attribute(type),"index");
    			redirTimeOut=setTimeout(redirectTo,5000,paramList.redirectLink);
    	}
    	
    }
    
    
    stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreenHasChanged);
    function fullScreenHasChanged(e:Event){
    	if (stage.displayState==StageDisplayState.FULL_SCREEN){
    		if (chatIsAllowed!=false){
    			keyz.visible=true;
    		}
    		fChat.visible=true;
    		fChat.onScreen=true;
    		stage.focus = fChat.inputText;
    		fChat.inputText.text=chatInput.inputText.text;
    		fChat.inputText.scrollH=fChat.inputText.maxScrollH;
    		keyz.x=5;
    		keyz.y=stage.stageHeight-50;
    		fChat.x=stage.stageWidth-5;
    		fChat.y=keyz.y;
    	}else{
    		if (originalViewSize!=viewSize){
    			screenSize(null);
    		}
    		stage.focus = chatInput.inputText;
    		keyz.visible=false;
    		fChat.visible=false;
    	}
    }
    keyz.visible=false;
    fChat.visible=false;
    
    
    var tipWin:SendTipMessage=null;
    function loadTipWindow(){
    	if (tipWin!=null){
    		return;
    	}
    	if (paramList.tipFileLink!=undefined){
    		tipWin = new SendTipMessage();
    		this.addChild(tipWin);	
    		tipWin.x=WIDTH/2;
    		tipWin.y=HEIGHT/2;
    	}	
    }
    
    
    function receivedTip(userId,userName, amount){
    	var tipWin = new TipSentMessage();
    	this.addChild(tipWin);	
    	tipWin.x=WIDTH/2;
    	tipWin.y=HEIGHT/2;
    	
    	if (userId==paramList.userId){
    		tipWin.setTexts( translationXML.@tipSuccess , translationXML.@tipYouSent+" "+amount+" "+translationXML.@tipCredits+"." );
    	}else{
    		tipWin.setTexts( translationXML.@tipHeaderHim , userName+" "+translationXML.@tipHeSent+" "+amount+" "+translationXML.@tipCredits+"." );
    	}
    }
    
    function failedTip(amount){
    	var tipWin = new TipSentMessage();
    	this.addChild(tipWin);	
    	tipWin.x=WIDTH/2;
    	tipWin.y=HEIGHT/2;	
    	
    	tipWin.setTexts( translationXML.@tipFailed , translationXML.@tipFailedMes );
    }
    
    function chatAllowance(allow){
    	if (allow=="0"){
    		chatIsAllowed=false;
    		var temp=setTimeout(disableSending,200);
    	}
    }
    function disableSending(){
    	if (!chatIsAllowed){
    		chatInput.disableSending();
    		fChat.disableSending();
    	}
    }

    I hope someone can help me with this.

    Much appreciated.

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    It would be more helpful if you posted a sample of the xml.
    If each user is represented by a <viewer> node and all viewer nodes are within a <list> node then you want to lookup myXML.list.viewer.length()

  3. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    4
    Quote Originally Posted by jAQUAN View Post
    It would be more helpful if you posted a sample of the xml.
    If each user is represented by a <viewer> node and all viewer nodes are within a <list> node then you want to lookup myXML.list.viewer.length()
    Thank you, jAQUAN. I figured it out, eventually. I actually used myXML.list.viewer.length(), however I should've put it after the loading of the XML, not before it.


    Problem solved, thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center