ну, ребята, у меня есть небольшая проблема здесь, у меня есть 3 контейнера и XML с n узлами ... я хочу поместить в контейнеры любое значение XML, это значение не может быть одним старым значением и в контейнерах не должно иметь одинаковое значение ... у меня есть этот код в as3, но он не работает: S
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
public class Pruebas extends Sprite
{
public var arr:Array = new Array("valor0","valor1","valor2","valor3","valor4","valor5")
public var str1:String=arr[0];
public var str2:String=arr[1];
public var str3:String=arr[2];
public var te1:TextField = new TextField();
public var te2 :TextField = new TextField();
public var te3 :TextField = new TextField();
public var btn :MovieClip = new MovieClip();
public function Pruebas()
{
te1.text = str1;
te2.text = str2;
te3.text = str3;
addChild(te1);
addChild(te2);
addChild(te3);
te2.x = 50;te3.x=100;
btn.graphics.beginFill(0xff00ff);
btn.graphics.drawCircle(151,150,15);
addChild(btn);
btn.addEventListener(MouseEvent.CLICK,cambiar);
}
public function cambiar(e:Event):void{
var minLimit:uint = 0;
var maxLimit:uint = arr.length-1;
var range:uint = maxLimit - minLimit;
var someNum:Number = Math.ceil(Math.random()*range) + minLimit;
if(str1 == arr[someNum]){
while(str1 == arr[someNum]){
someNum = Math.ceil(Math.random()*range) + minLimit;
}
str1 = arr[someNum];
}else{
str1 = arr[someNum];
}
someNum= Math.ceil(Math.random()*range) + minLimit;
if(str2 == arr[someNum]){
while(str2 == arr[someNum]){
someNum = Math.ceil(Math.random()*range) + minLimit;
}
str2 = arr[someNum];
}else{
str2 = arr[someNum];
}
someNum= Math.ceil(Math.random()*range) + minLimit;
if(str3 == arr[someNum]){
while(str3 == arr[someNum] || str3 ==str1 || str3 == str2){
someNum = Math.ceil(Math.random()*range) + minLimit;
}
str3 = arr[someNum];
}else{
str3 = arr[someNum];
}
te1.text = str1;
te2.text = str2;
te3.text = str3;
}
}
}
Эдуардо Проверьте этот код, что этот код я сделал
if(imgactual == myXML.internas.item[someNum].@numero){
while(imgactual == myXML.internas.item[someNum].@numero){
someNum = Math.ceil(Math.random()*range) + minLimit;
}
imgactual = myXML.internas.item[someNum].@numero
}else{
imgactual = myXML.internas.item[someNum].@numero
}
someNum= Math.ceil(Math.random()*range) + minLimit;
if((imgpostactual == myXML.internas.item[someNum].@numero) || (imgpostactual == imgactual) ){
while(imgpostactual == myXML.internas.item[someNum].@numero || imgpostactual == imgactual){
someNum = Math.ceil(Math.random()*range) + minLimit;
}
imgpostactual = myXML.internas.item[someNum].@numero
}else{
imgpostactual = myXML.internas.item[someNum].@numero
}
someNum= Math.ceil(Math.random()*range) + minLimit;
if((imgpreactual == myXML.internas.item[someNum].@numero) || (imgpostactual == imgpreactual) || (imgpreactual == imgactual)){
while((imgpreactual == myXML.internas.item[someNum].@numero) || (imgpostactual == imgpreactual) || (imgpreactual == imgactual)){
someNum = Math.ceil(Math.random()*range) + minLimit;
}
imgpreactual = myXML.internas.item[someNum].@numero;
}else{
imgpreactual = myXML.internas.item[someNum].@numero;
}
trace(imgactual);
trace(imgpreactual);
trace(imgpostactual);
плохо с этим кодом в том, что всегда цикл занимает много времени: S, и я думаю, что он не работает: S