Zurück   Flashforum > Flash und Server > Flash und Datenbanken

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 11-12-2011, 22:25   #1 (permalink)
Neuer User
 
Registriert seit: Apr 2010
Beiträge: 6
Question Eine zweite Variable ausgeben in Flash

Hallo zusammen, ich hoffe ihr könnt mir weiterhelfen,
habe ihr ein Login sript der beim login eine Variable von der Mysql datenbank ab ruft.
Das wer hier (user_bio) dies würd dann an die Flash datei übergeben als (result_text).
So nun zu meinen problem.
Ich bekomme es nicht hin das er auch eine zweite Variable ausgibt beispiel dan in der datenbank (user_bio2) und in Flash (result_text2).

Hier die Datei Source.zip
Skorpien ist offline   Mit Zitat antworten
Alt 13-12-2011, 09:56   #2 (permalink)
Neuer User
 
Registriert seit: Apr 2010
Beiträge: 6
Question Erläuterung

Hier mal die scripts für AS und PHP Vielleicht ist das einfacher.

Flash AS script
Code:
package actions {
	
	/*
	always extend a class using movieclip instead of sprite when using flash.
	*/

	import flash.display.MovieClip;
	import flash.events.*;
	import flash.net.*;
	import flash.text.*;
	
	/*
	create our class
	*/
	
	public class main extends MovieClip {
		
		public function main ():void {

			/*
			buttonMode gives the submit button a rollover
			*/
			
			submit_button.buttonMode = true;

			/*
			what this says is that when our button is pressed, the checkLogin function will run
			*/

			submit_button.addEventListener(MouseEvent.MOUSE_DOWN, checkLogin);
			
			/*
			set the initial textfield values
			*/
			
			username.text = "";
			password.text = "";
		
		}

		/*
		the function to check login
		*/
		
		public function checkLogin (e:MouseEvent):void {
		
			/*
			check fields before sending request to php
			*/
			
			if (username.text == "" || password.text == "") {
				
				/*
				if username or password fields are empty set error messages
				*/
				
				if (username.text == "") {
				
				username.text = "Enter your username";
				
				} 
				
				if (password.text == "") {
				
				password.text = "Enter your password";
				
				}
			
			} else {
				
				/*
				init function to process login
				*/
			
				processLogin();
			
			}
		
		}
		
		/*
		function to process our login
		*/
		
		public function processLogin ():void {
			
			/*
			variables that we send to the php file
			*/
		
			var phpVars:URLVariables = new URLVariables();
			
			/*
			we create a URLRequest  variable. This gets the php file path.
			*/
			
			var phpFileRequest:URLRequest = new URLRequest("php/controlpanel.php");
			
			/*
			this allows us to use the post function in php
			*/
			
			phpFileRequest.method = URLRequestMethod.POST;
			
			/*
			attach the php variables to the URLRequest
			*/
			
			phpFileRequest.data = phpVars;
			
			/*
			create a new loader to load and send our urlrequest
			*/
			
			var phpLoader:URLLoader = new URLLoader();
			phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;			
			phpLoader.addEventListener(Event.COMPLETE, showResult);
			
			/*
			now lets create the variables to send to the php file
			*/
			
			phpVars.systemCall = "checkLogin";
			phpVars.username = username.text;
			phpVars.password = password.text;
			
			/*
			this will start the communication between flash and php
			*/
			
			phpLoader.load(phpFileRequest);
		
		}
		
		/*
		function to show the result of the login
		*/
		
		public function showResult (event:Event):void {
			
			/*
			
			this autosizes the text field
			
			***** You will need to import flash's text classes. You can do this by: 
			
			import flash.text.*;
			
			*/
			
			result_text.autoSize = TextFieldAutoSize.LEFT;
			
			/*
			this gets the output and displays it in the result text field
			*/
			
			result_text.text = "" + event.target.data.systemResult;
		
		}
	
	}

}
und der PHP script
PHP-Code:
<?php 

/*
connect to our database
*/

include_once "connect.php";

/*
we post the variables we recieve from flash
*/

$username $_POST['username'];
$password $_POST['password'];

/* 
if flash called the login system the code below runs
*/

if ($_POST['systemCall'] == "checkLogin") {
    
/*
The * means the query initally selects all the records in the database.
Then the query filters out any records that are not the same as what the user entered.
*/


$sql "SELECT * FROM users WHERE username='$username' AND password='$password'";

$query mysql_query($sql);

/*
This counts how many records match our query
*/

$login_counter mysql_num_rows($query);

/*
if $login_counter is greater we send a message back to flash and get the data from the database
*/

if ($login_counter 0) {

/*
we use a while loop to get the user's bio. mysql_fetch_array gets all the field's data for the particular record.
*/

while ($data mysql_fetch_array($query)) {
    
/*
gets the user_bio value from the selected record
*/

$userbio $data["user_bio"];

/*
use the print function to send values back to flash
*/

print "systemResult=$userbio";

}

} else {

print 
"systemResult=The login details dont match our records.";

}

}

?>
Skorpien ist offline   Mit Zitat antworten
Alt 13-12-2011, 10:33   #3 (permalink)
Flash-Designer
 
Benutzerbild von Martin Kraft
 
Registriert seit: May 2006
Ort: Wiesbaden
Beiträge: 6.164
Wenn Du in Flash mehrere Varibalen verabeiten willst, musst Du mit PHP auch mehrer übergeben.

Ich bin kein PHP-Spezialist, aber Deinen Code müsstest Du wohl so abändern:
PHP-Code:
$i 1;
while ( 
$data mysql_fetch_array($query) ) {
    if (
$i 1) print "&";
    print 
"userbio".$i."=".urlencode($data["user_bio"]);
    
$i++;

Und mit AS liest Du diese urlencodierten Variablen dann analog in einer Schleife aus:
ActionScript:
  1. result_text.text = "";
  2.  
  3. var data:Object = event.target.data as Object;
  4. var iName:String;
  5. var i:uint = 1;
  6.  
  7. while( (iName = "userbio" + i) in data ) {
  8.     result_text.text += data[iName] + "\n";
  9.     i++;
  10. }
Da URLVariables aber IMHO generell etwas murksig sind, würde ich Dir empfehlen, stattdessen mit XML zu arbeiten. Mehr zu diesem Thema findest Du über die Links in meiner Signatur.
__________________
Viele Grüße // Martin

Martin Kraft // Interaktionsdesign

Hilfreiche Websites:
// Hilfe zur Adobe Flash Plattform
// ActionScript 2 Referenz
// ActionScript 3 Referenz
// ActionScript 3 Arbeitshandbuch
// weitere Flash Ressourcen

Bitte keine Flashfragen per PM oder Profilnachricht! Dafür ist das Forum da!
Martin Kraft ist offline   Mit Zitat antworten
Alt 13-12-2011, 22:36   #4 (permalink)
Neuer User
 
Registriert seit: Apr 2010
Beiträge: 6
ok danke habe es soweit hin bekommen,
aber wir mus ich das schreiben das er die 2 Variable auf ruft

PHP-Code:
if ($login_counter 0) {

/*
we use a while loop to get the user's bio. mysql_fetch_array gets all the field's data for the particular record.
*/

$i 1;
while ( 
$data mysql_fetch_array($query) ) {
    if (
$i 1) print "&";
    print 
"userbio".$i."=".urlencode($data["user_bio"]);
    
$i++;


}
}
?> 
PHP-Code:
        public function showResult (event:Event):void {
            
        
result_text.text "";
     
    var 
data:Object event.target.data as Object;
    var 
iName:String;
    var 
i:uint 1;
     
    while( (
iName "userbio" iin data ) {
        
result_text.text += data[iName] + "\n";
        
i++;
        
    } 

    } 


}

Skorpien ist offline   Mit Zitat antworten
Alt 13-12-2011, 22:50   #5 (permalink)
Flash-Designer
 
Benutzerbild von Martin Kraft
 
Registriert seit: May 2006
Ort: Wiesbaden
Beiträge: 6.164
Zitat:
Zitat von Skorpien Beitrag anzeigen
aber wir mus ich das schreiben das er die 2 Variable auf ruft
Was meinst Du damit
__________________
Viele Grüße // Martin

Martin Kraft // Interaktionsdesign

Hilfreiche Websites:
// Hilfe zur Adobe Flash Plattform
// ActionScript 2 Referenz
// ActionScript 3 Referenz
// ActionScript 3 Arbeitshandbuch
// weitere Flash Ressourcen

Bitte keine Flashfragen per PM oder Profilnachricht! Dafür ist das Forum da!
Martin Kraft ist offline   Mit Zitat antworten
Alt 14-12-2011, 08:47   #6 (permalink)
Neuer User
 
Registriert seit: Apr 2010
Beiträge: 6
Also ich meine da mit,
ich Ruffe jetzt nur von der Datenbank user_bio auf und gebe den Text aus auf result_text in Flash wie ich das vorher auch schon hatte.

So nun möchte ich aber das er nicht nur die user_bio ab fragt sondern auch user_bio2 und das aus gibt in result_text2

und das immer weiter führe da ich um 30 bis 40 Daten ab rufen muss.
Skorpien ist offline   Mit Zitat antworten
Alt 14-12-2011, 10:39   #7 (permalink)
Flash-Designer
 
Benutzerbild von Martin Kraft
 
Registriert seit: May 2006
Ort: Wiesbaden
Beiträge: 6.164
Aber genau das macht der Code von oben doch?! Z.Z. werden die Ergebnisse nur eben in ein einziges Textfeld geschrieben...
__________________
Viele Grüße // Martin

Martin Kraft // Interaktionsdesign

Hilfreiche Websites:
// Hilfe zur Adobe Flash Plattform
// ActionScript 2 Referenz
// ActionScript 3 Referenz
// ActionScript 3 Arbeitshandbuch
// weitere Flash Ressourcen

Bitte keine Flashfragen per PM oder Profilnachricht! Dafür ist das Forum da!
Martin Kraft ist offline   Mit Zitat antworten
Alt 14-12-2011, 12:27   #8 (permalink)
Neuer User
 
Registriert seit: Apr 2010
Beiträge: 6
Ja das ist richtig,
brauche aber alle ab fragen in verschiedenen Textfeldern,
so das ich 40 Textfeldern in Flash habe und in der Datenbank
unter dem User 40 Tabellen.
Die alle gleichzeitig ab rufe werden wenn sich der User ein logt um bestimmte Handlungen im Flash aufzurufen.

Geändert von Skorpien (14-12-2011 um 12:31 Uhr)
Skorpien ist offline   Mit Zitat antworten
Alt 14-12-2011, 12:32   #9 (permalink)
Flash-Designer
 
Benutzerbild von Martin Kraft
 
Registriert seit: May 2006
Ort: Wiesbaden
Beiträge: 6.164
So gibt man userbio1-n in (vorher angelegten) Textfeldern result_text1-n aus:
ActionScript:
  1. var data:Object = event.target.data as Object;
  2. var iName:String;
  3. var i:uint = 1;
  4.      
  5. while( (iName = "userbio" + i) in data ) {
  6.     this["result_text"+i].text += data[iName] + "\n";
  7.     i++;
  8. }
__________________
Viele Grüße // Martin

Martin Kraft // Interaktionsdesign

Hilfreiche Websites:
// Hilfe zur Adobe Flash Plattform
// ActionScript 2 Referenz
// ActionScript 3 Referenz
// ActionScript 3 Arbeitshandbuch
// weitere Flash Ressourcen

Bitte keine Flashfragen per PM oder Profilnachricht! Dafür ist das Forum da!
Martin Kraft ist offline   Mit Zitat antworten
Alt 16-12-2011, 11:35   #10 (permalink)
Neuer User
 
Registriert seit: Apr 2010
Beiträge: 6
Danke dir für deine mühe habe mich entscheiden es auf AS2 zu programmieren kenne mich da einwenig besser aus.
Skorpien ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an


Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
[Flash CS3] PHP Variable in FLASH ausgeben ohne ECHO Spanky11 Flash Einsteiger 5 02-03-2010 23:40
onclick eine Variable mit Text füllen und ausgeben WurstKuchen Alternative Technologien 13 17-09-2007 18:08
Session Variable in Flash ausgeben neo14 PHP und MySQL 1 31-05-2006 13:17
An ein zweite Flash eine Variable übergeben Muadib2K Flash 4 und Flash 5 6 16-04-2002 07:24
eine Variable per getURL ausgeben Maicel HTML und CSS 4 16-02-2002 20:15


Alle Zeitangaben in WEZ +1. Es ist jetzt 00:14 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele