Ciao,
questo è l'errore che viene fuori sia in flax che flash durante la compilazione di un file .as
A file found in a source-path can not have more than one externally visible definition.
Che vuol dire?
Questo è il codice che ho cercato di compilare
GrazieCodice PHP:
// VirtualZoo class
package
{
import flash.display.Sprite;
import zoo.*;
public class VirtualZoo extends Sprite
{
private var pet;
public function VirtualZoo()
{
this.pet = new VirtualPet("Stan");
pet.eat(new Apple()); // Feed Stan an apple
pet.eat(new Sushi()); // Feed Stan some sushi
// Assign the pet's old name to the local variable oldName
//var oldName = pet.getName();
// Give the pet a new name
//pet.setName("Marcos");
}
}
}
// VirtualPet class
package zoo
{
import flash.utils.setInterval;
import flash.utils.clearInterval;
public class VirtualPet
{
internal var petName;
private var currentCalories = 1000;
private var creationTime;
private static var maxNameLength = 20;
private static var maxCalories = 2000;
// Le calorie che consuma durante la digestione
private static var caloriesPerSecond = 100;
// Id del set interval per la digestione
private var digestIntervalID;
public function VirtualPet(name)
{
this.creationTime = new Date();
this.petName = name;
digestIntervalID = setInterval(digest, 1000);
}
private function digest ()
{
// If digesting more calories would leave the pet's currentCalories at
// 0 or less...
if (currentCalories - VirtualPet.caloriesPerSecond <= 0)
{
// ...stop the interval from calling digest()
clearInterval(digestIntervalID);
// Then give the pet an empty stomach
currentCalories = 0;
// And report the pet's death
trace(getName() + " has died.");
}
else
{
currentCalories -= VirtualPet.caloriesPerSecond;
trace(getName() + " digested some food. It now has " + currentCalories + " calories remaining.");
}
}
public function setName (newName)
{
if (newName.length > VirtualPet.maxNameLength)
{
newName = newName.substr(0, VirtualPet.maxNameLength);
}
else if (newName == "")
{
return;
}
petName = newName;
}
public function getName()
{
return petName;
}
// setter method AKA mutator method, from AS3.0 modifier method
public function eat(foodItem)
{
// If this pet is dead...
if (currentCalories == 0)
{
// ...quit this method without modifying currentCalories
trace(getName() + " is dead. You can't feed it.");
return;
}
if (foodItem is Apple)
{
if (foodItem.hasWorm())
{
trace("The " + foodItem.getName() + " had a worm. " + getName()
+ " didn't eat it.");
return;
}
}
var newCurrentCalories = currentCalories + foodItem.getCalories();
if (newCurrentCalories > VirtualPet.maxCalories)
{
currentCalories = VirtualPet.maxCalories;
}
else
{
currentCalories = newCurrentCalories;
}
trace(getName() + " ate some " + foodItem.getName() + ". It now has " + currentCalories + " calories remaining.");
}
// getter method AKA accesser method, from AS3.0 retriever method
public function getHunger()
{
return currentCalories / VirtualPet.maxCalories;
}
public function getAge()
{
var currentTime = new Date();
var age = currentTime.time - this.creationTime.time;
return age;
}
}
}
// Food class
package zoo
{
public class Food
{
private var calories;
private var name;
public function Food (initialCalories)
{
setCalories(initialCalories);
}
public function getCalories ()
{
return calories;
}
public function setCalories (newCalories)
{
calories = newCalories;
}
public function getName ()
{
return name;
}
public function setName (newName)
{
name = newName;
}
}
}
// Apple class
package zoo
{
public class Apple extends Food
{
// Set the default number of calories for an Apple object to 100
private static var DEFAULT_CALORIES = 100;
private var wormInApple;
public function Apple (initialCalories = 0)
{
// If no calorie value or a negative calorie value was specified
// for this particular object...
if (initialCalories <= 0)
{
// ...use the default value
initialCalories = Apple.DEFAULT_CALORIES;
}
super(initialCalories);
wormInApple = Math.random() >= .5;
// Set the food name for all Apple objects
setName("Apple");
}
public function hasWorm ()
{
return wormInApple;
}
}
}
// Sushi class
package zoo
{
public class Sushi extends Food
{
private static var DEFAULT_CALORIES = 500;
public function Sushi (initialCalories = 0)
{
if (initialCalories <= 0)
{
initialCalories = Sushi.DEFAULT_CALORIES;
}
super(initialCalories);
setName("Sushi");
}
}
}



Rispondi quotando

