w 2 krokach??

Technologia Flash, czyli animacja na potrzeby stron WWW to świat daleko odbiegły od zwykłego programowania i kodu. Zapytaj o pomoc i podziel się z nami Twoimi problemami z zakresu Flasha.
WacekPL
Posty: 9
Rejestracja: pn sty 07, 2008 4:31 pm

w 2 krokach??

Post autor: WacekPL »

ten kod wykonuje sie w 2 krokach... trzeba 2 razy nacisnac buton zeby wyswietlily sie 2 zmienne ktos wie jak zrobic zeby wykonywalo sie odrazu podczas nacisniecia butona?

_root.buton1.onRelease=function(){
if (validTxt(pole1) && validTxt(pole2)) {

pole1.restrict = "0-9";
pole2.restrict = "0-9";

a=pole1.text;
b=pole2.text;

pole4.text = a+" "+b

} else {
pole4.text = "Wpisz jakies dane!! tylko cyframi!! :P";
}

};
Marek_bf
Administrator
Posty: 4419
Rejestracja: czw lut 24, 2005 2:14 am
Kontakt:

Re: w 2 krokach??

Post autor: Marek_bf »

1. Popraw temat na sensowny
2. Wklej sobie w pusty plik i przetestuj:

Kod: Zaznacz cały

//
// te wywołania olej i tak już masz te obiekty na scenie
var pole1:TextField = createInputTextField(this, 20, 20);
var pole2:TextField = createInputTextField(this, 20, 50);
var pole4:TextField = createInputTextField(this, 20, 80);
var button1:MovieClip = createButton(this, 20, 110);
// ################################## //
// ################################## //
// ################################## //



// !!! TO Ciebie powinno interesować: 
pole1.restrict = "0-9";
pole2.restrict = "0-9";
//
button1.onRelease = function() {
	if (validTxt(pole1) && validTxt(pole2)) {
		pole4.text = pole1.text + " " + pole2.text;
	} else {
		pole4.text = "wypełnij wszystkie pola";
	}
};



// ################################## //
// ################################## //
// ################################## //
//
function validTxt(myTxt:TextField):Boolean {
	return myTxt.length > 0 ? true : false;
}
// te funkcje olej służą tylko do tego przykładu
// tworzą pola tekstowe i button
function createInputTextField(targetMc:MovieClip, xPoz:Number, yPoz:Number):TextField {
	var newDepth:Number = targetMc.getNextHighestDepth();
	var newName:String = "txt" + newDepth;
	var myInputTextField:TextField = targetMc.createTextField(newName, newDepth, xPoz, yPoz, 200, 22);
	myInputTextField.border = true;
	myInputTextField.borderColor = 0x000000;
	myInputTextField.type = "input";
	return myInputTextField;
}
//
function createButton(targetMc:MovieClip, xPoz:Number, yPoz:Number):MovieClip {
	var newDepth:Number = targetMc.getNextHighestDepth();
	var newName:String = "mc" + newDepth;
	var myButton:MovieClip = targetMc.createEmptyMovieClip(newName, newDepth);
	myButton._x = xPoz;
	myButton._y = yPoz;
	myButton.lineStyle(0, 0x999999, 100);
	myButton.beginFill(0xcccccc, 100);
	myButton.moveTo(0, 0);
	myButton.lineTo(0, 22);
	myButton.lineTo(200, 22);
	myButton.lineTo(200, 0);
	myButton.endFill();
	return myButton;
}
ODPOWIEDZ