Exlcuding a specific value from an Array and changing the background color

First of all, hi!
I’m Sux2bu, new to the forum and partially new to some advanced feats from AS3 :slight_smile:

So, 8 weeks ago I started with my GameDevelopment branch of the MediaTechnology tree at my school, and I am currently in my 1st week of the 2d Semester (or Period, as we call it here), and AS3 is introduced this time (last Period were GameMaker and XNA).
There’s a problem though… I have to work with Arrays now, and last time I worked with Arrays was during PHP last year; almost half a year ago >_<"

Here’s what we have to do for the 1st Assignment:
Make a sort of lottery system for Christmass; Make sure names aren’t drawn more than once, and that someone can’t draw him/herself.

This is the code for the first assignment:

package{
    import flash.display.MovieClip;
    import flash.text.TextField;
    import flash.events.MouseEvent;
    
    public class Opdracht1 extends MovieClip{
        
        public function Opdracht1():void{
            //Buttonmodes
            Loten_btn.buttonMode = true;
            //Event Listeners
            Loten_btn.addEventListener(MouseEvent.CLICK, LotenVanNamen);
            //variabelen
            var TextVisible:Boolean = false;
            var ArrayText:TextField = new TextField();
            var Namen:Array = new Array();
            //Waardes van de variabelen
            /*Start*/Namen             = ["Kyrsie","Troy","Chris","Linde","Martin"];
            //LootNamen             = ["Kyrsie","Troy","Chris","Linde","Martin"];
            ArrayText.x         = 50;
            ArrayText.y         = 100;
            ArrayText.width     = 550;
            ArrayText.height     = 400;
            ArrayText.text         = "";
        
            //Tekst laten verschijnen
            function LotenVanNamen(event:MouseEvent){
                if(TextVisible != true){
                    TextVisible = true;
                    addChild(ArrayText);
                }else{
                    TextVisible = false;
                    removeChild(ArrayText);
                }
            }
            for(var namen:int = 0; namen < Namen.length; namen++){
            //Getal kiezen en direct in een String zetten
                var LootGetal:Number = Math.round(Math.random() * (Namen.length-1));
                var LootNaam:String = String(LootGetal);
                var ArrayNaam:String = String(namen);
                if(ArrayNaam != LootNaam){
                //Naam aan een ArrayGetal koppelen
                if(namen == 0){
                    ArrayNaam = "Kyrsie";
                }
                if(namen == 1){
                    ArrayNaam = "Troy";
                }
                if(namen == 2){
                    ArrayNaam = "Chris";
                }
                if(namen == 3){
                    ArrayNaam = "Linde";
                }
                if(namen == 4){
                    ArrayNaam = "Martin";
                }
                //Naam aan een LootGetal koppelen
                if(LootGetal == 0){
                    LootNaam = "Kyrsie";
                }
                if(LootGetal == 1){
                    LootNaam = "Troy";
                }
                if(LootGetal == 2){
                    LootNaam = "Chris";
                }
                if(LootGetal == 3){
                    LootNaam = "Linde";
                }
                if(LootGetal == 4){
                    LootNaam = "Martin";
                }
                ArrayText.appendText(ArrayNaam + " maakt een surprise voor " + LootNaam + "
" + "
");
                }else{
                    if(ArrayNaam == LootNaam){
                    ArrayText.appendText("FAAL!!" + "
" + "
");
                    }
                }
            }
        }
    }
}

The variable names, function names and texts are in Dutch.
LootGetal = DrawNumber; The Number Drawed that will later on be transfered into a name.
LootNaam = DrawName; The name, converted from the Drawn number.
ArrayNaam = ArrayName; the name from the Array that will be place in order from 0 to 4.

Right now, the problems I am encountering is the fact that when ArrayNaam equals LootNaam a new name is drawn (not in the above code, but in an earlyer code), but there was still the problem that something like Linde draws Linde is possible (duhr… -_-").
So, how do I exclude a specific value so that this can not happen?

That would bring me a good step in another direction :slight_smile:

The second problem is that I have to make sure names aren’t drawn more than once. So something like:
**Linde draws Martin,

Troy draws Martin**

happens.

3rd; It bothers me that I use such an insaneley huge piece of code just to give numericals a String value (the endless list of if() statements). Any easyer way? I’m sure there has to be one… I have not found one however.

That pretty much sums up Assignment 1 :slight_smile:

Now, on to the 2d Assignment:
Work with external files (.txt files) to load in variables, pictures and such.
Make sure a picture is loaded this way - works. Easymode ;D
Make sure the background color is changed through an external (.txt) file.
code:

package{
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    
    public class Opdracht2 extends MovieClip{
        
        var LaadFoto:Loader = new Loader();
        var ColorChange:Boolean = new Boolean;
        
        public function Opdracht2():void{
            //Variabelen laden
            var LaadVari:URLLoader = new URLLoader();
            LaadVari.dataFormat = URLLoaderDataFormat.VARIABLES;
            LaadVari.addEventListener(Event.COMPLETE, GeladenVari);
            LaadVari.load(new URLRequest("Opdracht2Vari.txt"));
            //Foto's laden
            LaadFoto.contentLoaderInfo.addEventListener(Event.COMPLETE, GeladenFoto);
            LaadFoto.load(new URLRequest("4Chan.gif"));
            //Button eigenschappen
            Color_BTN.addEventListener(MouseEvent.CLICK, ColChange);
            ColorChange = false;
            //BG eigenschappen
            var LaadKleuren:URLLoader = new URLLoader();
            LaadKleuren.dataFormat = URLLoaderDataFormat.VARIABLES;
            LaadKleuren.addEventListener(Event.COMPLETE, GeladenKleur);
            LaadKleuren.load(new URLRequest("Opdracht2Kleuren.txt"));
            Color_BTN.buttonMode = true;
        }
        public function GeladenVari(evt:Event):void{
            LaadFoto.x = evt.target.data.Xpositie;
            LaadFoto.y = evt.target.data.Ypositie;
        }
        public function GeladenFoto(evt2:Event):void{
            addChild(LaadFoto);
        }
        public function ColChange(evt3:MouseEvent):void{
            if(ColorChange != true){
                ColorChange = true;
            }else{
                ColorChange = false;
            }
        }
        public function GeladenKleur(evt4:Event):void{
            //Kleur Bepalen
            if(ColorChange != true){
            graphics.lineStyle(0, 0xFFFFFF);
            graphics.beginFill(evt4.target.data.Kleur1);
            graphics.drawRect(0,0, 550, 400);
            graphics.endFill();
            }else{
                if(ColorChange == true){
                graphics.lineStyle(0, 0xFFFFFF);
                graphics.beginFill(evt4.target.data.Kleur3);
                graphics.drawRect(0,0, 550, 400);
                graphics.endFill();
                }
            }
        }
    }
}

Browsing Google (which is your best friend, and also led me here), I found out that the backgroundcolor can’t be changed during run-time; thus several sites advised to make an existing object and use the gotoAndStop()] Method to switch between colours.
That seemed kind of weak… so I pulled the beginFill method from the dusty shelf from last year, and came up with the drawing a square (background) through code; makes it easyer :slight_smile: less switching between screens o-o

However, the final if() - else statement doesn’t work. The start value of the if(ColorChange != true) works (which will define the start color). Switching the value makes the background change; so I can state that it actually works according to the assignment. Only problem is; when I press the button, changin the Boolean to true, the color doesn’t change from Kleur(Color)1 to Kleur3.

This is an alternative I used, but comes with the same outcome:

public function GeladenKleur(evt4:Event):void{
            //Kleur Bepalen
            graphics.lineStyle(0, 0xFFFFFF);
            if(ColorChange != true){
            graphics.beginFill(evt4.target.data.Kleur1);
            }else{
                if(ColorChange == true){
                graphics.beginFill(evt4.target.data.Kleur3);
                }
            graphics.drawRect(0,0, 550, 400);
             graphics.endFill();
            }

So, any solution to this?

If I can get help with these two assignments, they’re complete.
And before you ask; No. It does not help asking my teacher because all I get out of him is “Sorry, can’t tell. Otherwise I’d tell the answer” with a look in his eyes as if he doesn’t know what’s going on.

Greetings,

Sux2bu