Forum Flash, Actionscript, PHP e MySQL
invio variabile con POST ad un form in php

 
Nuovo Topic   Rispondi    Forum Flash, Actionscript, PHP e MySQL » ActionScript & Server Side
Precedente  Successivo 
Autore Messaggio
pettedemon
nuovo utente
nuovo utente



Registrato: 12/11/09 20:52
Messaggi: 2

MessaggioOggetto: invio variabile con POST ad un form in php
Inviato: 12.11.09 | 20:58
Rispondi citando

Ciao a tutti!
Non so più dove sbattere la testa!
Devo inviare una variabile, un punteggio di un gioco in flash, ad un form in php....
Non riesco in nessuna maniera a visualizzare la variabile che nel mio caso è -score- .
Qui il codice actionscript, dove ho modificato il finale , pero' non riesco a inviare la variabile...
 
Codice:
Stage.align = "tl";//aligns flash top left
Stage.scaleMode = "Scale";//makes objects not stretch when page is resized

//define vars
var segmentNumber:Number = 0;
var segmentLength:Number = new Number;
var segmentDistance:Number = new Number;
var currentSegX:Number = new Number;
var currentSegY:Number = new Number;
var currentSegR:Number = new Number;
var turnIncriment:Number = new Number;
var speed:Number = new Number;
var addSegInc:Number = 7;
var yumNum:Number = 0;
var numberOfSegs:Number = new Number;
var score:Number = 0;
var scoreInc:Number = 10;


//get xml
var snakeGameXML:XML = new XML();
snakeGameXML.ignoreWhite = true;
snakeGameXML.onLoad = function(bSuccess:Boolean):Void  {
    if (bSuccess) {
        //get the variables from the xml
        segmentLength = Number(snakeGameXML.firstChild.attributes.segmentLength);
        segmentDistance = Number(snakeGameXML.firstChild.attributes.segmentDistance);
        startSegX = Number(snakeGameXML.firstChild.attributes.currentSegX);
        startSegY = Number(snakeGameXML.firstChild.attributes.currentSegY);
        startSegR = Number(snakeGameXML.firstChild.attributes.currentSegR);
        turnIncriment = Number(snakeGameXML.firstChild.attributes.turnIncriment);
        speed = Number(snakeGameXML.firstChild.attributes.speed);
        gameHeight = Number(snakeGameXML.firstChild.attributes.gameHeight);
        gameWidth = Number(snakeGameXML.firstChild.attributes.gameWidth);
        timeBetweenElongate = Number(snakeGameXML.firstChild.attributes.timeBetweenElongate)* 1000;
    }else{
        trace("xml did not load, use defaults");
        //these are the default vars for if you aren't using the xml. 
        segmentLength = 500;
        segmentDistance = 7;
        startSegX = 100;
        startSegY = 30;
        startSegR = 90;
        turnIncriment = 5;
        speed =3;
        gameHeight = Stage.height;
        gameWidth = Stage.width;
        timeBetweenElongate = 1000;
    };
    createInterface();
    attachStartScreen();
};

function createInterface(){
    this.attachMovie("header", "header_mc", 43, {_x:gameWidth - 250, _y:5});//this is where the score is
    this.createEmptyMovieClip("pointsScoredGroup_mc", 44);//this is where the +10 goes when you hit an apple
    createRipple();
};

function createRipple(){
    this.createEmptyMovieClip("ripples_mc", 55);//create mc for ripples
    var rippleNum:Number = 0;
    ripple = new Object();
    ripple.interval = function() {
        rippleNum++;
        var randomX:Number = Math.round(Math.random()* (gameWidth - 40))+20;//random x and y for ripple
        var randomY:Number = Math.round(Math.random()* (gameHeight - 40))+20;
        var rippleScale:Number = Math.round(Math.random()* 80)+ 80;//random scale
        ripples_mc.attachMovie("ripple", "ripple_mc", rippleNum, {_x:randomX, _y:randomY, _xscale:rippleScale, _yscale:rippleScale});//attach ripple
    }
    setInterval(ripple, "interval", 500 );//attach a ripple every 1/2 second
}

function updateScore(){
    var scoreText:String = "SCORE: " + score;//score text
    header_mc.score_txt.text = scoreText;
    header_mc.scoreShadow_txt.text = scoreText;//write text in shadow
};




function attachStartScreen(){
    //this is the start screen
    this.createEmptyMovieClip("start_mc", 744);
    start_mc._alpha = 0;
    start_mc._x = (gameWidth - 350)/2;//define position
    start_mc._y = (gameHeight - 350)/2;
    start_mc.attachMovie("startScreen", "startScreen_mc", 2);
    tweenAlpha("start_mc", 100, false);//tween fade in
    start_mc.startScreen_mc.startButton_mc.onRelease = function(){//start button
        score = 0;
        updateScore();
        startSnake(segmentLength);
        attachYum();
        tweenAlpha("start_mc", 0, true);//fade start button out
        segmentInterval = setInterval(segments, "interval", timeBetweenElongate);//periodically make snake longer
    };
    
};

function attachEndScreen(){
    //this is the end screen
    this.createEmptyMovieClip("end_mc", 744);
    end_mc._x = (gameWidth - 350)/2;//define position
    end_mc._y = (gameHeight - 350)/2;
    end_mc.attachMovie("endScreen", "endScreen_mc", 2);
//    end_mc.attachMovie("header_pette","header_pette_mc", 4);

    //end_mc.attachMovie("header_pette", "endScreen_mc", 3);
    //updateScore();

stop();

};





//start the snake
function startSnake(segToAdd:Number):Void{
    //starting point for the snake
    currentSegX = startSegX;
    currentSegY = startSegY;
    currentSegR = startSegR;
    snake_mc.removeMovieClip();//kill the old snake
    this.createEmptyMovieClip("snake_mc", 10);//make new snake
    snake_mc._alpha = 0;//start invisible
    tweenAlpha("snake_mc", 100, false);//fade snake in
    yums_mc.removeMovieClip();//get rid of apples
    this.createEmptyMovieClip("yums_mc", 409);//make new clip for apples
    for(var i:Number = 1;i<segToAdd;i++){
        segmentNumber++;
        currentSegX += segmentDistance;//add segments
        snake_mc.attachMovie("bodySeg", "seg"+segmentNumber+"_mc", segmentNumber, {_x:currentSegX, _y:currentSegY, _rotation:currentSegR}); 
    };
    
    snake_mc.attachMovie("head", "head_mc", 1, {_x:currentSegX, _y:currentSegY, _rotation:currentSegR});//attach snake head
    numberOfSegs = segToAdd;
    moveSnake();
};
//where to put the next segment
function segPosition():Array{
    
    if(Key.isDown(Key.RIGHT)) { //when you click the right button change angle
         currentSegR += turnIncriment;
     }else if (Key.isDown(Key.LEFT)) { //when you click the left button change angle
         currentSegR += -turnIncriment;
     }
    currentSegX += Math.sin( (Math.PI* currentSegR)/180 )* segmentDistance;//determine where next seg x and y go
    currentSegY += -(Math.cos( (Math.PI* currentSegR)/180 )* segmentDistance);
    
    segmentNumber++;
    
    var positionsArray:Array = new Array;//create array for positions
    //if the snake goes off the screen put the on the opposite side
    if(currentSegX > gameWidth + 16){
        currentSegX = -16;
    }else if(currentSegX < -16){
        currentSegX = gameWidth + 16;
    };
    if(currentSegY > gameHeight + 16){
        currentSegY = -16;
    }else if(currentSegY < -16){
        currentSegY = gameHeight + 16;
    };
    
    positionsArray.push(currentSegX, currentSegY, currentSegR);//push positions to array
    return positionsArray;
};
//check the hit areas
function checkHit(){
    //check to see if the head hits the snake
    for(var i:Number = segmentNumber - numberOfSegs;i<segmentNumber;i+=5){
        if(eval("snake_mc.seg"+i+"_mc").hitTest(snake_mc.head_mc.hitArea_mc)){
            delete snake_mc.onEnterFrame;//stop moving snake
            //clearInterval(segmentInterval);//stop adding segments
            //tweenAlpha("snake_mc", 0, true);//fade snake out
            //
            //mettere funzione per visualizzare lo score e la registrazione
            //
            


attachEndScreen();

            //
            //
            //
            //
            //
            //
            
        };
        
        
        
    };
};
function checkYumHit():Void{
    //see if the apples hit the snake head
    if (eval("yums_mc.yum"+yumNum+"_mc").hitTest(snake_mc.head_mc.hitArea_mc)){
        
        pointsScoredGroup_mc.attachMovie("pointsScored", "pointsScored"+yumNum+"_mc", yumNum, {_x:eval("yums_mc.yum"+yumNum+"_mc")._x, _y:eval("yums_mc.yum"+yumNum+"_mc")._y});
        eval("pointsScoredGroup_mc.pointsScored"+yumNum+"_mc").score_txt.text = "+" + scoreInc;//change score text
        
        tweenAlpha("pointsScoredGroup_mc.pointsScored"+yumNum+"_mc", 0, true);
        
        eval("yums_mc.yum"+yumNum+"_mc").removeMovieClip();//remove apple

        score += scoreInc;//add to score
        updateScore();//update score
        attachYum();
    };
};


function attachYum():Void{
    //attach an apple
    yumNum++;
    //random position of the apple
    var randomX:Number = Math.round(Math.random()* (gameWidth - 40))+20;
    var randomY:Number = Math.round(Math.random()* (gameHeight - 40))+20;
    var randomR:Number = Math.round(Math.random()* 360);
    //var randomY:Number = 
    yums_mc.attachMovie("yumYum", "yum"+yumNum+"_mc", yumNum, {_x:randomX, _y:randomY, _rotation:randomR, _alpha:0});
    tweenAlpha("yums_mc.yum"+yumNum+"_mc", 100, false);//fade alpha in
    
};
//peridically make it longer
segments = new Object();
segments.interval = function() {
    numberOfSegs += addSegInc;//add segments
}


//move the snake
function moveSnake():Void{
    
    snake_mc.onEnterFrame = function(){
        checkYumHit();//see if you are eating an apple
        
        for(var i:Number = 0;i<speed;i++){
            var positionsArray:Array = segPosition();//get positions of next seg
            
            checkHit();//check to see if snake hits itself
            
            snake_mc.head_mc._x = positionsArray[0];//move head
            snake_mc.head_mc._y = positionsArray[1];//move head
            snake_mc.head_mc._rotation = positionsArray[2];//move head
            snake_mc.head_mc.swapDepths(segmentNumber + 100);//move head depth
            
            snake_mc.attachMovie("wake", "wake"+segmentNumber+"_mc", segmentNumber + 99, {_x:positionsArray[0], _y:positionsArray[1], _rotation:positionsArray[2]});//attach wake
        
            snake_mc.attachMovie("bodySeg", "seg"+segmentNumber+"_mc", segmentNumber, {_x:positionsArray[0], _y:positionsArray[1], _rotation:positionsArray[2]}); //attach body seg
        
            var lastSegNum:Number = segmentNumber-numberOfSegs;//number of last segment
            eval("snake_mc.seg"+lastSegNum+"_mc").removeMovieClip();//remove the last segment
            //make the tail taper off and get skinny at neck
            if(i == 1){
                //make the first part skinny
                var smallestWidth:Number = 30;//skinniest part of the neck
                var numberToGrow:Number = Math.round(numberOfSegs/3)//grows from the first 1/4
                if(numberToGrow > 30){
                    numberToGrow = 30;
                };
                
                for(var iii:Number = 0;iii<numberToGrow;iii++){
                    eval("snake_mc.seg"+(segmentNumber - iii)+"_mc")._xscale = iii* ((100-smallestWidth)/numberToGrow) + smallestWidth;
                };
                //how many taper off
                var numberToTaper:Number = Math.round(numberOfSegs/2);//tapers the last 1/2
                if(numberToTaper > 45){
                    numberToTaper = 45;
                };
                for(var ii:Number = 0;ii<numberToTaper;ii++){
                    
                    eval("snake_mc.seg"+(lastSegNum + ii)+"_mc")._xscale = ii* (100/numberToTaper);
                };
            };
        };
    };
};

//tween fade
easeType = mx.transitions.easing.Strong.easeOut;
var tweenTime = .5;
tweenAlpha = function(tweenClipAlpha:String, tweenEndAlpha:Number, thenRemove:Boolean){
    //fade in and out function
    tweenClipAlpha = eval(tweenClipAlpha);
    alphaTween = new mx.transitions.Tween(tweenClipAlpha, "_alpha", easeType, getProperty(tweenClipAlpha, _alpha), tweenEndAlpha, 1, true);
    if(thenRemove == true){//if true remove the clip when faded in or out
        alphaTween.onMotionFinished = function(){
            eval(tweenClipAlpha).removeMovieClip();
        };
    };
};

snakeGameXML.load("snakeGame.xml");//loads xml



il mio pulsante è un semplice
 
Codice:
on (release)
{

getURL("http://mary:8888/registra.php", "_self", "POST");
}


ma non passa nessuna variabile!!!
qui potete anche vedere il sorgente del gioco
scarica
Torna in cima
Profilo Messaggio privato  
Sponsor
Coach
amministratore
amministratore


Età: -1981
Registrato: 31/01/03 13:50
Messaggi: 4546
Località: Verona

MessaggioOggetto:
Inviato: 03.12.09 | 15:24
Rispondi citando

Ciao pettedemon,
hai risolto il problema?

Siccome il problema è relativo all'invio di dati da Flash a PHP, potresti tralasciare "tutto il codice del gioco" e veder eil problema di per sè?

Hai per caso fatto una ricerca nel Forum? Ci sono un sacco di topics che trattano l'argomento.
Conosci la classe LoadVars?

____________________________________________________________


Il Forum è uno strumento di condivisione, oltre a fare DOMANDE, si possono anche dare RISPOSTE!
Torna in cima
Profilo Messaggio privato [ Nascosto ] HomePage Yahoo Messenger MSN Messenger Skype
pettedemon
nuovo utente
nuovo utente



Registrato: 12/11/09 20:52
Messaggi: 2

MessaggioOggetto:
Inviato: 04.12.09 | 20:32
Rispondi citando

Ciao,
sinceramente ho risolto, copiando e incollando un po' di codice da altri esempi, non ho capito pero' cosa ho fatto di preciso.
Ho visto e letto che è molto + indicato usare la classe LoadVars ma non la "padroneggio" + di tanto...
Cmq ti ringrazio!
Torna in cima
Profilo Messaggio privato  
Mostra prima i messaggi di:   
Nuovo Topic   Rispondi    Forum Flash, Actionscript, PHP e MySQL » ActionScript & Server Side Tutti i fusi orari sono GMT + 2 ore
Pagina 1 di 1

Discussioni Simili
Topic Autore Forum Risposte Ultimo Messaggio
Nessun nuovo messaggio invio variabile post wicked ActionScript & Server Side 5 13.03.07 | 02:09 Leggi gli ultimi messaggi
Coach
Nessun nuovo messaggio form con invio files Helenchan PHP 1 11.04.08 | 17:35 Leggi gli ultimi messaggi
ZobaZ
Nessun nuovo messaggio PROBLEMINO FORM INVIO MAIL - FLASH e PHP andr3a07 ActionScript & Server Side 4 07.04.08 | 11:23 Leggi gli ultimi messaggi
Coach
Nessun nuovo messaggio Perdita dati durante invio form Eugene PHP 1 27.03.08 | 19:08 Leggi gli ultimi messaggi
ZobaZ
Nessun nuovo messaggio GET o POST cli PHP 8 10.06.04 | 14:33 Leggi gli ultimi messaggi
Coach



 
Vai a:  
Non puoi inserire nuovi Topic in questo forum
Non puoi rispondere ai Topic in questo forum
Non puoi modificare i tuoi messaggi in questo forum
Non puoi cancellare i tuoi messaggi in questo forum
Non puoi votare nei sondaggi in questo forum
Non puoi allegare files in questo forum
Puoi downloadare gli allegati in questo forum



Powered by phpBB © 2001, 2002 phpBB Group - phpBB SEO Designed by coachdesign - © 2003-2005