RE: [Flashcoders] understanding the for loop - EXTENDED HELP NEEDED.
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
Re: [Flashcoders] understanding the for loop - EXTENDED HELP NEEDED.
hi Corban, //ALL ISSUES ARE OCCURING IN THIS LINE OF CODE FROM WHAT I UNDERSTAND //COULD ANYONE HELP ME OUT WITH THIS? rfcClip.container.attachMovie(imgID); the other two arguments for attachMovie are name:String and depth:Number. :) to clarify Andreas' advice to use var, if you only need it locally, declare it locally. for example, randomPos is only used inside loadImages, but you declare it in the beginning of your script. that's not necessary, you can declare it in the beginning of your function. also, i disagree with him on using function foo () { over var foo:Function = function () {, but i guess that's really a matter of preference. just do it like whatever feels more comfortable with you. hth, mark On 2/2/06, Corban Baxter [EMAIL PROTECTED] wrote: So I am trying to convert the scripts to AS2 and get strict datatyping to work but nothing seems to work the way I imagined it to work. I tried to do what I could best and nothing still is working. All the data is in place but nothing will get my MC's to load in the images from the library... [code] ///varibles setup var layoutNum:Number; var oldNum:Number; var setsArray:Array = new Array(); var totalSetsNLayout:Number; var totalImagesNLayout:Array = new Array(); var imagesToGrab:Number; var imgArray:Array = new Array(); var rfcsArray:Array = new Array(); var randomSet:Number; var oldSet:Number; var img:String; var myMC:String; var randomPos:Number; var rfcClip:MovieClip; var imgID:String; function selectLayoutNum(){ //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); } function getSetsNLayout(layoutNum){ setsArray = [null, 3, 3, 3, 3, 4]; totalSetsNLayout = setsArray[layoutNum]; trace(totalSetsNLayout: + totalSetsNLayout); gatherImages4Layout(totalSetsNLayout, layoutNum); } function gatherImages4Layout(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 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); myMC = lay + layoutNum + _img + i; rfcsArray.push(myMC); } //trace(imgArray= [ + imgArray + ]); //trace( ); //trace(rfcsArray = [ + rfcsArray + ]); gotoAndPlay(lay_ + layoutNum); } //loadImages is called in an interval when the playhead hits the marker specified //like lay_2 etc //loadImgInterval = setInterval(loadImages, 2000, imagesToGrab); function loadImages(imagesToGrab){ if(imagesToGrab == 0){ //stop loading images clearInterval(loadImgInterval); trace(hitting the clear); }else{ randomPos = random(imagesToGrab)+1; rfcClip = rfcsArray[randomPos]; imgID = imgArray[randomPos]; rfcsArray.splice(randomPos, 1); imgArray.splice(randomPos, 1); //select and image id trace(imgID: + imgID); //select corisponding rfcClip trace(rfcClip: + rfcClip); //ALL ISSUES ARE OCCURING IN THIS LINE OF CODE FROM WHAT I UNDERSTAND //COULD ANYONE HELP ME OUT WITH THIS? rfcClip.container.attachMovie(imgID); imagesToGrab--; clearInterval(loadImgInterval); loadImgInterval = setInterval(loadImages, 2000, imagesToGrab); } trace(imagesLeftToLoad: + imagesToGrab); trace( ); } selectLayoutNum(); stop(); [/code] Corban Baxter |rich media designer |www.funimation.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Corban Baxter Sent: Thursday, February 02, 2006 10:45 AM To: flashcoders@chattyfig.figleaf.com Subject: RE: [Flashcoders] understanding the for loop - EXTENDED HELP NEEDED. 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
RE: [Flashcoders] understanding the for loop - EXTENDED HELP NEEDED.
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
RE: [Flashcoders] understanding the for loop - EXTENDED HELP NEEDED.
That would be great I'd love to see other approaches to this. But things are looking up I simplified that function into the one before it and it works fine. I am hoping to get this working fairly shortly. If so I will send you the file. Its going to be fun to look at I'm sure... Corban Baxter | rich media designer | www.funimation.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: Wednesday, February 01, 2006 5:48 PM To: Flashcoders mailing list Subject: RE: [Flashcoders] understanding the for loop - EXTENDED HELP NEEDED. I gotta run home, maybe someone else can help - I'll try and write up some examples if I can later - but relax, don't go nuts on us. And you didn't have to change your sig just because I teased you a little! :) Seriously, I'll try and work up an example that might be a little cleaner if I can find some time tonight or tomorrow. Jason Merrill | E-Learning Solutions | icfconsulting.com -Original Message- From: [EMAIL PROTECTED] [mailto:flashcoders- [EMAIL PROTECTED] On Behalf Of Corban Baxter Sent: Wednesday, February 01, 2006 6:42 PM To: Flashcoders mailing list Subject: RE: [Flashcoders] understanding the for loop - EXTENDED HELP NEEDED. 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
RE: [Flashcoders] understanding the for loop - EXTENDED HELP NEEDED.
Thanks a million Jason! Corban Baxter | rich media designer | www.funimation.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Corban Baxter Sent: Wednesday, February 01, 2006 5:53 PM To: Flashcoders mailing list Subject: RE: [Flashcoders] understanding the for loop - EXTENDED HELP NEEDED. That would be great I'd love to see other approaches to this. But things are looking up I simplified that function into the one before it and it works fine. I am hoping to get this working fairly shortly. If so I will send you the file. Its going to be fun to look at I'm sure... Corban Baxter | rich media designer | www.funimation.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: Wednesday, February 01, 2006 5:48 PM To: Flashcoders mailing list Subject: RE: [Flashcoders] understanding the for loop - EXTENDED HELP NEEDED. I gotta run home, maybe someone else can help - I'll try and write up some examples if I can later - but relax, don't go nuts on us. And you didn't have to change your sig just because I teased you a little! :) Seriously, I'll try and work up an example that might be a little cleaner if I can find some time tonight or tomorrow. Jason Merrill | E-Learning Solutions | icfconsulting.com -Original Message- From: [EMAIL PROTECTED] [mailto:flashcoders- [EMAIL PROTECTED] On Behalf Of Corban Baxter Sent: Wednesday, February 01, 2006 6:42 PM To: Flashcoders mailing list Subject: RE: [Flashcoders] understanding the for loop - EXTENDED HELP NEEDED. 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
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