Well, I am going to take a stab at strict formatting. Not sure how well this is 
going to go but wish me luck as I venture off. Hopefully I can get some help as 
I take this new road. I appreciate the insight Andreas,

//cb


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Andreas Rønning
Sent: Wednesday, February 01, 2006 6:25 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] understanding the for loop - EXTENDED HELP NEEDED.

I'm way, way too sleepy to pretend that i can give you any advice on 
your actual problem, but i CAN give you advice on your AS form.
Please dude, for the sake of your brain cells, start using strict typing 
and local variables, and when you can, lose the myMethod = 
function(param) syntax.
Semantically it makes sense in the myObject.myMethod = function setting, 
but putting it everywhere makes your code unreadable at a glance.

function myMethod(param){
}

Spotting the "function" at the beginning of the line hints your neurons 
at the code structure. This is how our brains work, one percept triggers 
a perception. You need to work with it to make it work less.
In the same way, spotting "myObject" ahead of "myFunction" tells us what 
scope we're dealing with. With no scope, where are we? Until we read the 
"= function" we might as well expect
myMethod = 2 or myMethod = new Donkey();

Methods/Functions should be as generic as can be, Not necessarily in 
function, but in form.. Again, for the sake of your mental health.
In this situation, you want a function that takes a horse and places it 
in its little horse-car so it can drive off to the races and win.
However, if the car is already operated by another horse, create a new 
car and put the horse in that instead. True to life.

functun putHorseInCar(horse){
    if(!myCar.occupied){
       myCar.driver = horse;
    }else{
       newCar = new Car();
       newCar.driver = horse;
    }
}

Immediatly you're in a heap of dung, since this function is written to 
only incorporate one specific car, and you'll need multiple functions 
like it to match all TWO HUNDRED THOUSAND cars in the world! BAD!
Of course, you'd write a more generic function that takes more arguments 
and perhaps, with the luxury of forethought, you make it return a 
reference to the car that has been treated, because perhaps sometime you'd
like some feedback instead of just blindly trusting that the function 
does as you hope.

function putHorseInCar(horse:Horse,car:Car):Car{
    var someCar:Car = car;
    if(!someCar.occupied){
       someCar.driver = horse;
    }else{
       someCar= new Car();
       someCar.driver = horse;
    }
    return someCar;
}

I'm not saying you don't do this. I'm just reminding you and anyone else 
not feeling like kicking me in the balls yet that this kind of generic 
approach where a function may suddenly become useful in a setting for 
which it wasn't originally designed, simply because you wrote it with 
forethought and the wisdom of the ages, this kind of approach will SAVE 
YOUR ASS time and time again. Why? Because when you're 80, you'll rue 
the day you wilfully hurt your now-stagnating braincells.

A function is a guy you ask a favor. "Hey you, guy, i don't know what 
your job is, i don't know what you prefer to do, but would you mind 
photocopying this paperwork for me?". In "guy"'s world, the exact nature 
of the paperwork doesnt matter. It doesnt matter what you plan to do 
with it, and he shouldnt need to know; he needs to know how to use a 
photocopier of course but the nature of the paperwork shouldn't matter 
to him. In his world, the time where the papers enter his life until the 
time when they leave it, the papers lose all meaning. If he is unable to 
do as you ask because he didnt know that your paperwork required that he 
fold it into happy little origami birds and stomp on them repeatedly 
before xeroxing them, his life is miserable, and you probably won't get 
what you wanted from him.

Functions are innocent bystanders, not coworkers.

Speaking of innocent bystanders, don't send stray bullets flying all 
over the map.

selectLayoutNum = function(){
                //check if it was the last layout
                //set layoutNum
                layoutNum = random(5) +1;
                while(layoutNum == oldNum){
                        layoutNum = random(5) +1;
                }
                oldNum = layoutNum;
                trace("layoutNum: " + layoutNum);
                getSetsNLayout(layoutNum);
}

layoutNum! PIEAOWW *Ducks behind the counter*
oldNum! P'CHINNGGGggg *throws himself into the gutter*

These are near death experiences i could have AVOIDED had you only aimed 
them correctly and put "var" in front of them!
Variables, especially in functions, aren't fire and forget. They lie in 
wait like wolves, the smell of blood in their nostrils. And then!
Whammy. I'm willing to bet you've had bugs because of this in the past, 
and the sooner you get down with the var-ness, the better.

Anyway i'm just sleepy so don't think i'm trying to tell you off. I'm 
just pointing out shit that really killed my head back around flash 5 up 
til late MX, and
i feel your pain.

Cheers,

- Andreas

Corban Baxter wrote:
> Well it's kind of working. I'd love to have some help on this to get me
> going correctly. So with that said I'll try and explain what this is.
>
> Ok so we are creating a screensaver that has 5 img layouts/templates
> with different numbers of images per layout but they have empty MC's in
> place to place the images later.
>
> For each template we have created sets of images to choose from that
> will be placed in each template. These images have linkage id's in the
> lib.
>
> What we want to do is select a random "LAYOUT" (template). Then select
> images for each position in the layout/template at random from a set of
> images designed for each template. So with that said it's a mouth full.
>
> What I thought I could do is generate all this random stuff and create
> an array from it that stores my images to be used. Then I need to
> generate a list of MC's to place these images into. Which is more or
> less determined in each template but each template has a different # of
> images in it.
>
> NEXT issue is this. Once I have both array's one of "linkage id's" for
> the template and another array that holds my "MC references". I want to
> load these images into the corresponding MC but in another random order.
> (I know I know but we don't ever want ANYTHING to look the same twice). 
>
> So what I will have to do is then figure out a decent way to get the
> loading to work without killing myself.
>
> Now my new problem is flash is telling me my function "createMCrfcs " is
> some sorta infinite loop and can't finish the task. Which makes no sense
> cause I am more or less doing the same thing above. But what ever. I
> hope this makes sense and someone can throw some insight to me after
> typing all this! Thanks for listening boys!
>
> I'm going crazy and this might sound crazy but any help would be GREATLY
> appericated!!!!
>
>
> //setup vars
> clipNum = 1;
>
> selectLayoutNum = function(){
>               //check if it was the last layout
>               //set layoutNum
>               layoutNum = random(5) +1;
>               while(layoutNum == oldNum){
>                       layoutNum = random(5) +1;
>               }
>               oldNum = layoutNum;
>               trace("layoutNum: " + layoutNum);
>               getSetsNLayout(layoutNum);
> }
>
> getSetsNLayout = function(layoutNum){
>       setsArray = [null, 3, 3, 3, 3, 4];
>       totalSetsNLayout = setsArray[layoutNum];
>       trace("totalSetsNLayout: " + totalSetsNLayout);
>       gatherImages4Layout(totalSetsNLayout, layoutNum);
> }
>
> gatherImages4Layout = function(totalSetsNLayout, layoutNum){
>       totalImagesNLayout = [null, 9, 8, 6, 6, 11];
>       imagesToGrab = totalImagesNLayout[layoutNum];
>       trace("imagesToGrab: " + imagesToGrab);
>
>       
>       //dynamicly create array of images to be used in layout
>       imgArray = new Array();
>       for(i=0; i<=imagesToGrab; i++){
>               randomSet = random(totalSetsNLayout) + 1;
>               while(randomSet == oldSet){
>                       randomSet = random(totalSetsNLayout) + 1;
>               }
>               oldSet = randomSet;
>               
>               img = "layout" + layoutNum + "_set" + randomSet + "_img"
> + i;
>               imgArray.push(img);
>       }
>       trace("imgArray= [" + imgArray + "]");
>       gotoAndPlay("lay_" + layoutNum);
>       createMCrfcs(layoutNum, totalImagesNLayout);
> }
>
> createMCrfcs = function(layoutNum, totalImagesNLayout){
>       trace("totalSetsNLayout: " + totalSetsNLayout);
>       //create clip array...
>       rfcsArray = new Array();
>       for(p=0; p<=totalImagesNLayout; p++){
>               myMC = "lay" + layoutNum + "_img" + p;
>               rfcsArray.push(myMC);           
>       }
>       trace("rfcsArray = [" + rfcsArray + "]");
> }
>
> selectLayoutNum();
> stop();
>
>
>
>
> //cb
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>   

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to