samedi 10 décembre 2016

actionscript 3 MouseEvent random color

i'm just getting started programming and wanted to know how to make the cards i made in actions script a random color with a MouseEvent. I have to do this for a a school project in Animate (adobe). (This is also the first time using this website). This is my code:

This is the card.as:

package  {

import flash.display.MovieClip;
import flash.geom.ColorTransform;
import flash.text.TextField;


public class card extends MovieClip {

    //praperties
    public var cardNumber:int;
    public var cardColor:ColorTransform;
    public var cardType:String;
    public var minNum:Number;
    public var maxNum:Number;
    public var textBox:TextField;

    //constructor
    public function card() {

        cardType = randomCardType();

        cardNumber = 5;
        cardColor = randomcardColor();
        trace(cardColor);
        trace(cardType);
        transform.colorTransform = cardColor;

        textBox = new TextField();
        addChild(textBox);
        textBox.text = String(cardType + "\n" + cardNumber);
        textBox.width = 100;
        textBox.height = 100;
        textBox.border = true;
    }

            //methods
    public function printinfo() :void {
        trace("cardNumber: '" + cardNumber + "'");
    }

    public function randomcardColor():ColorTransform {
        var kleur:ColorTransform = new ColorTransform();
        kleur.color = (Math.random() * 0xFFFFFF); 
        return kleur;
    }

    public function randomCardType(){
        var Name:Array = ["Knight","Archer","Wizard","Priest"];
        var randomNum:int = Math.floor(Math.random()* Name.length);
        return Name[randomNum];
    }

    function randomRange(minNum:Number, maxNum:Number):Number {
            return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
    }

    public function checkcardColor (otherColor) {
        if (cardColor == otherColor) {
            return true;
        }

        else {
            return false;
        }
    }
}   

}

and this is the cardgame.as:

package  {

import flash.display.MovieClip;
import fl.motion.Color;


public class cardgame extends MovieClip {

    //proparties
    public var cardA:card;
    public var cardB:card;
    public var cardC:card;
    public var cardD:card;

    // constructor code
    public function cardgame() {

        cardA = new card();
        cardA.x = 100;
        cardA.y = 100;
        cardA.width = 100;
        cardA.height = 100;
        this.addChild(cardA);

        cardB = new card();
        cardB.x = 450;
        cardB.y = 100;
        cardB.width = 100;
        cardB.height = 100;
        this.addChild(cardB);

        cardC = new card();
        cardC.x = 450;
        cardC.y = 300;
        cardC.width = 100;
        cardC.height = 100;
        this.addChild(cardC);

        cardD = new card();
        cardD.x = 100;
        cardD.y = 300;
        cardD.width = 100;
        cardD.height = 100;
        this.addChild(cardD);

        showMeTheWorld();                   
    }

    //methods
    public function showMeTheWorld() {
        cardA.printinfo();
        cardB.printinfo();
        cardC.printinfo();
        cardD.printinfo();
    }
}

}

Aucun commentaire:

Enregistrer un commentaire