问题
I have no syntax errors when I run this code. I checked the variables and the functions in the action panel and it works fine. But, when I remove the codes from the action panel, and try to run the .as file nothing happens when I click the button. Here's my code:
package
{
import flash.display.*;
import flash.events.MouseEvent;
import flash.text.*;
import flash.display.MovieClip;
public class U1A4_Sommeil extends MovieClip
{
private var monMessage:TextField = new TextField;
private var maMiseEnForme: TextFormat = new TextFormat;
public function U1A4_Sommeil ()
{
btnSoumettre.addEventListener(MouseEvent.CLICK,Calcule);
}
private function Calcule (event:MouseEvent):void
{
maMiseEnForme.font= "Arial";
maMiseEnForme.size = 20;
maMiseEnForme.color = 0xFF0000;
maMiseEnForme.bold = true;
monMessage.autoSize = TextFieldAutoSize.LEFT;
monMessage.defaultTextFormat = maMiseEnForme;
monMessage.x = 260;
monMessage.y = 260;
monMessage.border = true;
var intAn : int = int(txtAn.text) - int(txtAnNaissance.text);
var intMois : int = int(txtMois.text) - int(txtMoisNaissance.text);
var intJour : int = int(txtJour.text) - int(txtJourNaissance.text);
var strResultat : String = ("Tu es agé de "+ (intAn*365+intMois*30+intJour) + " jours."
+ "\n"
+ "Tu as dormi " + ((intAn*365 + intMois*30 + intJour)*8) + " heures"
+ "\n"
+ "depuis ta naissance.");
monMessage.text = strResultat;
addChild (monMessage);
}
}
}
回答1:
I think that your have just to add your U1A4_Sommeil
class as your document class using your document properties :
Or, from File Menu > ActionScript Settings... then :
Hope that can help.
来源:https://stackoverflow.com/questions/28748305/flash-cs4-inactive-buttons