Ajudem a descobrir qual o erro

4 respostas
B

Olá pessoal fiz este código mas ta a dar 2 erros não percebo porque?Alguém me pode ajudar.
Obrigado
o código:

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout=“absolute” initialize="iniciaData()"
creationComplete=“init()”>

<mx:Script>
	<![CDATA[
		import mx.collections.ArrayCollection;
		import flash.utils.Timer;
		import flash.events.TimerEvent;
		
		// first arrays that are going to set the length of the array collection
		private var arrayFlor:Array;
		private var arrayElevat:Array;
		private var turn:Number = 0;
		private var secs:Number = 0;
		// these are the the array collections to store the ojects floor and elevator
		[Bindable]
		public var dispArrayElevat:ArrayCollection;
		public var dispArrayFlor:ArrayCollection;
		
		//this is the variable of type timer that fires every 1 sec
		private var t:Timer;
		
		// here is where we initiate the timer
		private function init() : void {
			t = new Timer(1000);	
			t.addEventListener(TimerEvent.TIMER, tempo);
			t.start();
		}
				// maybe I will need an array of buttons, the size of the floors
		// assing to each one the same function, match its index  
		
		
		public function iniciaData():void {
			dispArrayElevat = new ArrayCollection(arrayElevat); 
			dispArrayFlor = new ArrayCollection(arrayFlor); 
		}
		
		// this function is filling the array collection with the objects 
		// when the button "set" is clicked - you have to click it before ckicking a floor
		private function outPut(event:Event):void{
			arrayFlor= new Array(floorsNum.value);
			arrayElevat= new Array(elevatorNum.value);
			
			for(var i:Number=0; i< elevatorNum.value; i++) {
				dispArrayElevat.addItem(new Elevator(i,4,true));
				
			}
			for(var j:Number=0; j< floorsNum.value; j++) {
				dispArrayFlor.addItem(new Floor(j,4,false));
				
			}
		}
		
		
		// if a button is pressed this funtion hanges the floor state
		private function call(event:Event):void{
			var currentFloor:Number = Number(event.currentTarget.label);
			
			if(Already(currentFloor)){
				dispArrayFlor.getItemAt(currentFloor).setLightState(false);
				dispArrayFlor.getItemAt(currentFloor).setFloorState(1);
				output0.text = "" + dispArrayFlor.getItemAt(currentFloor).getFloorState();//output
			}
			else{
				dispArrayFlor.getItemAt(currentFloor).setFloorState(2);
				dispArrayFlor.getItemAt(currentFloor).setLightState(true);
			}
		}
		// this function checks if the elevator is already on a floor called 
		private function Already(floor:int):Boolean {
			var i:Number=0;
			for ( i = 0; i<dispArrayElevat.length; i++){
				if(floor == dispArrayElevat.getItemAt(i).getPosition()){
					return true;
				}
			}
			i++;
			return false;
		}
		// checks if any floor above has the state 2, "called"
		private function CalledAbove(index:Number):Boolean{
			var j:Number;
			for ( j = dispArrayFlor.length-1; j > index; j--){
				if(dispArrayFlor.getItemAt(j).getState() == 2){
					return true;
				}
			}
			return false;
		}
		// checks if any floor bellow has the state 2, "called"			
		private function isCalledBellow(index:Number):Boolean{
			var j:Number;
			for ( j = 0; j < index; j++){
				if(dispArrayFlor.getItemAt(j).getLightState() == true){
					return true;
				}
			}
			return false;
		}
		// this function is working in the first else, it checks if there are calls bellow but not above...BUG
		private function tempo(event:TimerEvent):void {
			
			var position:Number = dispArrayElevat.getItemAt(turn).getPosition();
			
			if( dispArrayElevat.getItemAt(turn).getDirection()==true && CalledAbove(position)==true ) {
				dispArrayElevat.getItemAt(turn).moveUP();
				turn++;
			}
			else if( dispArrayElevat.getItemAt(turn).getDirection()==false && isCalledBellow(position)==true ) {
				
				dispArrayElevat.getItemAt(turn).moveDown();
				turn++;	
			}
			else{
				dispArrayElevat.getItemAt(turn).switchDirection();
			}
			
			if(turn == dispArrayElevat.length -1) {
				turn=0;
			}
			
			output.text = "direction: "+dispArrayElevat.getItemAt(turn).getDirection()+"  Position: "+dispArrayElevat.getItemAt(turn).getPosition();//output
		}
		
		
	]]>
</mx:Script>


<mx:NumericStepper id="floorsNum" maximum="12" minimum="2" x="81" y="30" width="42"/>
<mx:NumericStepper id="elevatorNum" maximum="8" minimum="1" x="203" y="30" width="35"/>

<mx:Button id="setRC" x="262" y="30" label="Set" click="{outPut(event)}"/>

<mx:Label x="32" y="32" text="Floors:" fontSize="13" fontWeight="bold"/>
<mx:Label x="139" y="31" text="Elevators:" fontWeight="bold" fontSize="13"/>
<mx:Label x="360" y="57" text="Output:"/>
<mx:Label x="260" y="325" text="Output2:"/>

<mx:TextArea id="output0" text="" x="318" y="318" width="136" height="22"/>
<mx:TextArea id="output" text="" x="410" y="50" width="228" height="22"/>

<mx:Button id="b0" x="29" y="462" label="0" click="{call(event)}"/>
<mx:Button id="b1" x="29" y="432" label="1" click="{call(event)}"/>
<mx:Button id="b2" x="29" y="402" label="2" click="{call(event)}"/>
<mx:Button id="b3" x="29" y="372" label="3" click="{call(event)}"/>
<mx:Button id="b4" x="29" y="342" label="4" click="{call(event)}"/>
<mx:Button id="b5" x="29" y="312" label="5" click="{call(event)}"/>
<mx:Button id="b6" x="29" y="282" label="6" click="{call(event)}"/>
<mx:Button id="b7" x="29" y="252" label="7" click="{call(event)}"/>
<mx:Button id="b8" x="29" y="222" label="8" click="{call(event)}"/>
<mx:Button id="b9" x="29" y="192" label="9" click="{call(event)}"/>
<mx:Button id="b10" x="29" y="162" label="10" click="{call(event)}"/>
<mx:Button id="b11" x="29" y="132" label="11" click="{call(event)}"/>
<mx:Button id="b12" x="29" y="102" label="12" click="{call(event)}"/>

</mx:Application>

4 Respostas

Jesuino_Master

Acho melhor você colocar as tags de formatação do código [ code ] e [ / code ] para o pessoal visualizar melhor.

E outra sugestão é falar mais sobre o erro: Em que circunstâncias aparece, quais são exatamente os erros.

Só algumas dicas de como obter sucesso no fórum :slight_smile:

[]'s

B

vou colocar os 2 erros que dão a vermelho:

<?xml version=“1.0” encoding=“utf-8”?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout=“absolute” initialize="iniciaData()"
creationComplete=“init()”>

<mx:Script>

<![CDATA[

import mx.collections.ArrayCollection;

import flash.utils.Timer;

import flash.events.TimerEvent;
// first arrays that are going to set the length of the array collection

private var arrayFlor:Array;

private var arrayElevat:Array;

private var turn:Number = 0;

private var secs:Number = 0;

// these are the the array collections to store the ojects floor and elevator

[Bindable]

public var dispArrayElevat:ArrayCollection;

public var dispArrayFlor:ArrayCollection;

//this is the variable of type timer that fires every 1 sec
private var t:Timer;

// here is where we initiate the timer

private function init() : void {

t = new Timer(1000);

t.addEventListener(TimerEvent.TIMER, tempo);

t.start();

}

// maybe I will need an array of buttons, the size of the floors

// assing to each one the same function, match its index
public function iniciaData():void {

dispArrayElevat = new ArrayCollection(arrayElevat);

dispArrayFlor = new ArrayCollection(arrayFlor);

}
// this function is filling the array collection with the objects

// when the button “set” is clicked - you have to click it before ckicking a floor

private function outPut(event:Event):void{

arrayFlor= new Array(floorsNum.value);

arrayElevat= new Array(elevatorNum.value);
for(var i:Number=0; i>< elevatorNum.value; i++) {

[color=red]dispArrayElevat.addItem(new Elevator(i,4,true)); [/color]} ERRO: Call to a possibly undefined method Elevator

for(var j:Number=0; j< floorsNum.value; j++) {

dispArrayFlor.addItem(new Floor(j,4,false));   ERRO: Call to a possibly undefined method Floor

}
}

// if a button is pressed this funtion hanges the floor state

private function call(event:Event):void{

var currentFloor:Number = Number(event.currentTarget.label);
if(Already(currentFloor)){

dispArrayFlor.getItemAt(currentFloor).setLightState(false);

dispArrayFlor.getItemAt(currentFloor).setFloorState(1);

output0.text = “” + dispArrayFlor.getItemAt(currentFloor).getFloorState();//output

}

else{

dispArrayFlor.getItemAt(currentFloor).setFloorState(2);

dispArrayFlor.getItemAt(currentFloor).setLightState(true);

}

}

// this function checks if the elevator is already on a floor called

private function Already(floor:int):Boolean {

var i:Number=0;

for ( i = 0; i<dispArrayElevat.length; i++){

if(floor == dispArrayElevat.getItemAt(i).getPosition()){

return true;

}

}

i++;

return false;

}

// checks if any floor above has the state 2, "called"

private function CalledAbove(index:Number):Boolean{

var j:Number;

for ( j = dispArrayFlor.length-1; j > index; j){

if(dispArrayFlor.getItemAt(j).getState() == 2){

return true;

}

}

return false;

}

// checks if any floor bellow has the state 2, "called"

private function isCalledBellow(index:Number):Boolean{

var j:Number;

for ( j = 0; j < index; j++){

if(dispArrayFlor.getItemAt(j).getLightState() == true){

return true;

}

}

return false;

}

// this function is working in the first else, it checks if there are calls bellow but not aboveBUG

private function tempo(event:TimerEvent):void {

var position:Number = dispArrayElevat.getItemAt(turn).getPosition();

if( dispArrayElevat.getItemAt(turn).getDirection()==true && CalledAbove(position)==true ) {

dispArrayElevat.getItemAt(turn).moveUP();

turn++;

}

else if( dispArrayElevat.getItemAt(turn).getDirection()==false && isCalledBellow(position)==true ) {
dispArrayElevat.getItemAt(turn).moveDown();

turn++;

}

else{

dispArrayElevat.getItemAt(turn).switchDirection();

}
if(turn == dispArrayElevat.length -1) {

turn=0;

}

output.text = "direction: "+dispArrayElevat.getItemAt(turn).getDirection()+" Position: "+dispArrayElevat.getItemAt(turn).getPosition();//output
}

]]>
</mx:Script>

<mx:NumericStepper id=“floorsNum” maximum=“12” minimum=“2” x=“81” y=“30” width=“42”/>
<mx:NumericStepper id=“elevatorNum” maximum=“8” minimum=“1” x=“203” y=“30” width=“35”/>

<mx:Button id=“setRC” x=“262” y=“30” label=“Set” click="{outPut(event)}"/>

<mx:Label x=“32” y=“32” text=“Floors:” fontSize=“13” fontWeight=“bold”/>
<mx:Label x=“139” y=“31” text=“Elevators:” fontWeight=“bold” fontSize=“13”/>
<mx:Label x=“360” y=“57” text=“Output:”/>
<mx:Label x=“260” y=“325” text=“Output2:”/>

<mx:TextArea id=“output0” text="" x=“318” y=“318” width=“136” height=“22”/>
<mx:TextArea id=“output” text="" x=“410” y=“50” width=“228” height=“22”/>

<mx:Button id=“b0” x=“29” y=“462” label=“0” click="{call(event)}"/>
<mx:Button id=“b1” x=“29” y=“432” label=“1” click="{call(event)}"/>
<mx:Button id=“b2” x=“29” y=“402” label=“2” click="{call(event)}"/>
<mx:Button id=“b3” x=“29” y=“372” label=“3” click="{call(event)}"/>
<mx:Button id=“b4” x=“29” y=“342” label=“4” click="{call(event)}"/>
<mx:Button id=“b5” x=“29” y=“312” label=“5” click="{call(event)}"/>
<mx:Button id=“b6” x=“29” y=“282” label=“6” click="{call(event)}"/>
<mx:Button id=“b7” x=“29” y=“252” label=“7” click="{call(event)}"/>
<mx:Button id=“b8” x=“29” y=“222” label=“8” click="{call(event)}"/>
<mx:Button id=“b9” x=“29” y=“192” label=“9” click="{call(event)}"/>
<mx:Button id=“b10” x=“29” y=“162” label=“10” click="{call(event)}"/>
<mx:Button id=“b11” x=“29” y=“132” label=“11” click="{call(event)}"/>
<mx:Button id=“b12” x=“29” y=“102” label=“12” click="{call(event)}"/>
</mx:Application>

andre.gil

Cara,

A classe Elevator e a classe Floor existem? Você importou elas?

[]'s

D

Cara,

Concordo com o andre.gil. Pelo que vi faltaram os imports destas duas classes.

[]'s
Diego

Criado 23 de março de 2010
Ultima resposta 25 de mar. de 2010
Respostas 4
Participantes 4