Adobe Flex
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Tutorialized ForumsWeb Design & DevelopmentAdobe Flex

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 6th, 2008, 10:08 AM
MrBaseball34 MrBaseball34 is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 2 MrBaseball34 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 7 sec
Reputation Power: 0
Using XMLList as dataprovider to DataGrid and adding rows

In the code below, I'm having trouble figuring out how to add rows to the grid. I have found only one tutorial and using it's techniques doesn't seem to work.

Can anyone help out here?

Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="initApp();">

 	<mx:Script>
 		<![CDATA[
  			import mx.rpc.events.ResultEvent;
  			import mx.rpc.events.FaultEvent;
  			import mx.controls.Alert;
  
     [Bindable]
     private var rosterInfo:XMLList;
     
     public function handleXML(event:ResultEvent):void
     {
       rosterInfo = event.result.option as XMLList;                
     }
     
     public function handleFault(event:FaultEvent):void
     {
       Alert.show(event.fault.faultString, "Error");
     }
     
     public function initApp():void
     {
       if (ExternalInterface.available)
         ExternalInterface.addCallback("addPlayer", addPlayer); 
     }
  			
  			public function addPlayer(player_name:String, jersey_: String, age_:String):void
     {
       (RosterList.dataProvider as XMLList).addItem(
         {playerid: 0, playername: player_name, jersey: jersey_, age: age_}
       );
     }
   ]]>
 	</mx:Script>
  <mx:HTTPService result="handleXML(event);" 
     	            fault="handleFault(event);" 
     	            id="xmlRPC" 
     	            resultFormat="e4x"
                  url="flexget_roster.php"
                  useProxy="false">
	   <mx:request xmlns="">
      <teamid>{teamid.text}</teamid>
	     <teampin>{teampin.text}</teampin>
	   </mx:request>
 	</mx:HTTPService>
 	<mx:Label x="56" y="32" text="Team ID" width="55" height="18" 
 	          textAlign="right" fontWeight="bold"/>
 	<mx:Label x="56" y="58" text="TeamPin" width="55" height="18" 
 	          textAlign="right" fontWeight="bold"/>
 	<mx:TextInput x="130" y="32" id="teamid" width="160" 
 	              height="22"/>
 	<mx:TextInput x="130" y="58" id="teampin" width="160" 
 	              height="22"/>
 	<mx:Button x="130" y="95" label="Get Roster" 
 	           click="xmlRPC.send();" width="160" height="22"/>
 	<mx:DataGrid dataProvider="{rosterInfo}"
 	             x="80" 
 	             y="141" 
 	             width="262" 
 	             height="306" 
 	             id="RosterList" 
 	             enabled="true" 
 	             editable="true" >
 	  <mx:columns>
 	    <mx:DataGridColumn headerText="playerid" 
                         dataField="playerid" 
                         visible="false"/>
      <mx:DataGridColumn headerText="Player Name" 
                         dataField="playername" />
      <mx:DataGridColumn headerText="Jersey" 
                         dataField="jersey" 
                         width="60"/>
      <mx:DataGridColumn headerText="Age" 
                         dataField="age" 
                         width="40"/>
    </mx:columns>
  </mx:DataGrid>
</mx:Application>

mySQL data:
Code:
    
  #
  # Table structure for table 'players'
  #
  
  CREATE TABLE `players` (
    `playerid` int(11) NOT NULL auto_increment,
    `teamid` int(11) NOT NULL,
    `jersey` varchar(3) default NULL,
    `playername` varchar(255) NOT NULL,
    `age` tinyint(4) default NULL,
    KEY `playerid` (`playerid`)
  ) ENGINE=MyISAM AUTO_INCREMENT=116 DEFAULT CHARSET=latin1;
  
  
  
  #
  # Dumping data for table 'players'
  #
  
  INSERT INTO `players` (`playerid`, `teamid`, `jersey`, `playername`, `age`) VALUES 
   ( 1,5,'34','Nolan Ryan',8),
  	( 2,5,'21','Roger Clemens',8),
  	( 3,5,'51','Randy Johnson',9),
  	( 5,5,'40','David Wells',12),
  	( 6,5,'56','Brad Lidge',15),
  	( 7,5,'55','Chad Qualls',9),
  	( 8,5,'17','Roy Oswalt',10),
  	( 9,5,'46','Andy Pettitte',11),
  	(10,5,'26','Mariano Rivera',13),
  	(11,6,'34','Nolan Ryan',9),
  	(12,6,'21','Roger Clemens',10),
  	(13,6,'2', 'Randy Johnson',13),
  	(14,6,'42','Bob Gibson',12),
  	(15,6,'19','David Wells',13),
  	(16,6,'4', 'Brad Lidge',12),
  	(17,6,'55','Chad Qualls',15),
  	(18,6,'68','Roy Oswalt',16),
  	(19,6,'41','Andy Pettitte',13),
  	(20,6,'26','Mariano Rivera',9),
  
  #
  # Table structure for table 'teams'
  #
  
  CREATE TABLE `teams` (
    `id` int(1) NOT NULL auto_increment,
    `teamname` varchar(20) NOT NULL default '',
    `division` char(2) NOT NULL default '',
    `email` varchar(45) NOT NULL default '',
    `active` tinyint(4) NOT NULL default '1',
    `PIN` int(4) NOT NULL default '1990',
    `link` varchar(255) default NULL,
    PRIMARY KEY  (`id`),
    UNIQUE KEY `id` (`id`),
    KEY `teamname` (`teamname`)
  ) ENGINE=MyISAM AUTO_INCREMENT=32 DEFAULT CHARSET=latin1;
  
  
  
  #
  # Dumping data for table 'teams'
  #
  
  INSERT INTO `teams` (`id`, `teamname`, `division`, `email`, `active`, `PIN`, `link`) VALUES 
   (1,'Blue Jays','AA','aa_blue_jays@oursite.com',1,1990,NULL)  ,
  	(2,'Orioles','AA','aa_orioles@oursite.com',1,2000,  NULL),
  	(3,'Yankees','AA','aa_yankees@oursite.com',1,2010,  NULL),
  	(4,'Penguins','A','american_peguins@oursite.com',1  ,2160,NULL),
  	(5,'Roadrunners','A','american_roadrunners@oursite  .com',1,2170,NULL),
  	(6,'Cardinals','A','american_cardinals@oursite.com  ',1,2180,NULL),
  	(7,'OPEN','','',1,1990,NULL);

HTML page to allow adding of Players to Roster:
Code:

<html>
<body>
<script language="javascript">
//<!--

function addPlayer()
{
  var player_name = document.getElementById('player_name').value;
  var age_ = document.getElementById('age_').value;
  var jersey_ = document.getElementById('jersey_').value;
  getFlexApp('RosterInfo').addPlayer(player_name, jersey_, age_);
}
//-->
</script>
<center>
  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  		id="RosterInfo" width="421" height="561"
  		codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
  		<param name="movie" value="RosterEdit.swf" />
  		<param name="quality" value="high" />
  		<param name="bgcolor" value="#869ca7" />
  		<param name="allowScriptAccess" value="always" />

  		<embed src="RosterEdit.swf" quality="high" bgcolor="#869ca7"
        			width="421" height="561" name="RosterInfo" align="middle"
        			play="true"
        			loop="false"
        			quality="high"
        			allowScriptAccess="always"
        			type="application/x-shockwave-flash"
        			pluginspage="http://www.adobe.com/go/getflashplayer">
  		</embed>
  </object>
  <br>
  <br>
  <table class="Roster">
    <tr>  
      <td>
        Enter Data then Click on the Add Player button
      </td>
    </tr>
    <tr>  
      <td>
        <table style="border-spacing:5px;" width="100%">
          <tr>
            <td style="border-style:none;padding:0px;">Player Name:</td>
            <td style="border-style:none;padding:0px;">
              <input id="player_name" type="text" />
            </td>
          </tr>
          <tr>
            <td style="border-style:none;padding:0px;">Jersey Number:</td>
            <td style="border-style:none;padding:0px;">
              <input id="jersey_" type="text" />
            </td>
          </tr>
          <tr>
            <td style="border-style:none;padding:0px;">Age:</td>
            <td style="border-style:none;padding:0px;">
              <input id="age_" type="text" />
            </td>
          </tr>
          <tr>
            <td colspan="2" style="border-style:none;padding:0px;">
              <input type="button" id="butAddPlayer" onclick="addPlayer()" value="Add Player" />
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
  </center>
</body>
</html>

PHP source for flexroster.php:
PHP Code:
<?php
  
function get_flex_roster($teamid$teampin) {
    include(
"/home/dbconnect.inc"); // has $dbuser, $dbpw, etc values...
    
mysql_connect($dbhost$dbuser$dbpw$dbname$pconnect);
    
$pinsql "SELECT PIN from teams WHERE id = $teamid";
    
$pinquery mysql_query($pinsql);
    if ((
mysql_num_rows($pinquery) == 0) || (mysql_result($pinquery0) <> $teampin)) {
      
$options = array("You did not enter a valid PIN for the team selected, try again.");
    } else {  
      
$teamsql "SELECT playerid, playername, jersey, age FROM players WHERE teamid = $teamid ORDER BY jersey, age";
      
      
$teamquery mysql_query($teamsql);
      
$str "";
      
$i 0;
      if (
mysql_num_rows($teamquery) > 0) {
        while (
$result mysql_fetch_assoc($teamquery)) {
          
$options[] = $result;
        }
      } else {     
        
$options = array("There are no players for this team, to add players, click the Add Player button.");
      }
    }
    return 
$options;
  }
?>

PHP source for flex_getroster.php
PHP Code:
<?php
  
require('flexroster.php');
  
$options get_flex_roster($_REQUEST["teamid"], $_REQUEST["teampin"]);
  
$results[] = "<options>";
  foreach (
$options as $roster)
  {
  
$results[] = "<option>
                  <playerid>" 
$roster['playerid'] . "</playerid>
                  <playername>" 
$roster['playername'] . "</playername>
                  <jersey>" 
$roster['jersey'] . "</jersey>
                  <age>" 
$roster['age'] . "</age>
                </option>"
;
  }
  
$results[] = "</options>";
  print 
implode("\n"$results);
?>

Last edited by MrBaseball34 : May 6th, 2008 at 10:16 AM.

Reply With Quote
Reply

Viewing: Tutorialized ForumsWeb Design & DevelopmentAdobe Flex > Using XMLList as dataprovider to DataGrid and adding rows


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway