Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Using The CreateTextBox Function In A Loop



hey I have a question...

I'm creating a sort of psuedo DBMS in flash and I'm having trouble populating my tables... I'm creating input textboxes for each of the input values.

My problem is this. The textboxes are being created in a for loop like this..

for(var i=0; i<recordsPerPage; i++){

var yellow = String("servId"+i);

this.createTextField(yellow, (i+13), 3.4, (23+17*i), 40, 24);
yellow.background = 0x000000
yellow.textColor = 0xcccccc;
.... etc.
}

The problem is that everytime the loop runs, it negates or overwrites that yellow in the yellow.background and other properties. But I need it to increment so that I can have multiple textboxes for a column. I've tried arrays too... Plz help!



KirupaForum > Flash > ActionScript 1.0/2.0
Posted on: 10-11-2004, 12:47 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Using The CreateTextBox Function In A Loop
hey I have a question...

I'm creating a sort of psuedo DBMS in flash and I'm having trouble populating my tables... I'm creating input textboxes for each of the input values.

My problem is this. The textboxes are being created in a for loop like this..

for(var i=0; i<recordsPerPage; i++){

var yellow = String("servId"+i);

this.createTextField(yellow, (i+13), 3.4, (23+17*i), 40, 24);
yellow.background = 0x000000
yellow.textColor = 0xcccccc;
.... etc.
}

The problem is that everytime the loop runs, it negates or overwrites that yellow in the yellow.background and other properties. But I need it to increment so that I can have multiple textboxes for a column. I've tried arrays too... Plz help!

LoadVars In A For Loop Not Executing .load Function Until For Loop Completed?
Ok so I have a simply for loop: ID[i] is a global array



Code:


for (i=0;i<12;i++)
{
var loadInfo:LoadVars = new LoadVars();
loadInfo.onLoad=function(success:Boolean)
{
if (success)
{
trace("whatever:"+loadInfo.myname);
}
else
{
trace("Nope");
}
loadInfo.load(ID[i]+".txt");
}



the problem I'm having is that the function doesn't execute until the for loop completes and then it executes 12 times in a row. Output is 'whatever: undefined' 11 times and then 'whatever: Bobble' (which corresponeds to the last .myname value as it should). Why is this? And how can I fix it? To be continued...

~NH

Function Inside For Loop; How To Give It Parameters Of The Loop
Hey!

This is the code:


Code:

for (i=0; i<5; i++) {
_root.createEmptyMovieClip("temp"+i, 1+i);


_root["temp"+i].beginFill(0xFF0000, 20 + (20*i));
_root["temp"+i].moveTo(0+(60*i), 0+(67*i));
_root["temp"+i].lineTo(100+(60*i), 0+(61*i));
_root["temp"+i].lineTo(100+(64*i), 100+(65*i));
_root["temp"+i].lineTo(0+(55*i), 100+(80*i));

_root["temp"+i].endFill();

_root["temp"+i].onRelease = function() {

trace("button Number = " +i);
}
}


So I made butttons and assigned each one an onRelease function. But each one needs to have assigned a variabile by the value "i" in the for loop.
When I write it like this the function itself is defined only after I click it and it ofcourse asigns all the buttons the same "i", the last value of "i" in the for loop.

How do I do it so I get first button with variable 1, second with 2,... ?

Thx.

Help: Trying To Get A Var To Loop Into An XML Function
Hi, I'm using XML with flash for the first time.

Project: Using XML get flash to duplicate a movieClip a certian number of times(in my case 4, 4 being the number of PageInfo sections in my XML file) and also bring in the correct unique information from each of the PageInfo sections into each of the duplicated clips.

Problem: I can duplicate the movieClips 4 times using an XML funcition, but the problem arises where I try to display the title names New Connect 1, New Connect 2, New Connect 3 and New Connect 4 into each of the duplicated movieClips.


from the code in frame 2

_root.NC_title = this.childNodes[0].childNodes[0].childNodes[1].childNodes;

above is my var that will bring in the text into my dynamic text filed this.childNodes etc etc tragets the correct depth to get the title information in my XML. Now of course this will only get the first title information. So I created var P and set it too loop 4 times as well to create 1,2,3 and 4 in order to set my NC_title to find and display XML info for title's 1,2,3 and 4.

Below is the script I tried at first:

_root.NC_title = this.childNodes[0].childNodes[0].childNodes[p].childNodes;

This only loops 1 time, because as I found out is not inside the loop that starts at frame 10. Now my problem is I don't know how to get that XML childNode script to work inside the frame 10 loop

I have tried using this line in various ways inside the frame 10 loop
and have always gotten back undefined for NC_title

I belive that I can only get that line to work in my first function, so I need to figure out how to get that part of the function to loop in frame 10


thanks ahead of time for any help





here is my file
http://www.leongaban.com/files/myfile.zip

Function Within For Loop
hi all, I am looking to put a custom function inside of a for loop that creates my text buttons. How would i go about doing this??

I have the following which draws a line fine:


addLine = function(){
this.lineStyle(1, 0x000000, 100);
this.moveTo(this._width, 4);
this.lineTo(this._width, 16);
}

.... and then within my for loop i have:

navBar["myBtn"+i].addLine();

I was hoping that this would run the function and draw the line but nothing happens. How do i run this function within my for loop??

thanx

How Do I Loop A Function?
The code below reverses playback at a frame at a time, I would like it to continue reversing the playback untiil it hits a certain frame.
How do i create a loop.

like: loop this command below until this happens...


rew_btn.onRelease = function(){
ballmove_mc.gotoAndStop(ballmove_mc._currentframe-1);
}


any comments greatly appreciated, I have checked out loop tutorials but have not seen it used i timeline control.
Any ideas?

thanks for helping
Ant

Loop A Function
How do I loop a function...I can't seem to get it to work.

Function In For Loop
I'm having some trouble making the following work in AS3. Basically I have different sets of buttons but on each set I want to be able to use a for loop to cut down on the code. Any help on the following line would be appreciated:

for (var m:int = 1; m<5; m++) {
root["m" + m + "_btn"].addEventListener(MouseEvent.CLICK, (root["m" + m + "B"]));
function (root["m" + m + "B"])(e:MouseEvent):void {
Tweener.addTween(cHM_mc, {alpha:0, time:0.5});
if (mBVal == 1) {
cHM_mc.addChild(root["mB" + m + "Loader"]);
market();
mBVal = 1;
} else if (mBVal != 1) {
cHM_mc.removeChildAt(0);
cHM_mc.addChild(root["mB" + m + "Loader"]);
market();
}
}
}

The Function is where everything is going wrong... it prompts me for an identifier and I just can't get it to work.

~ Ryan

Loop Function
Hi

I have an intro animation which is inside a function. So when I call that function the intro animation start.

Question: I want to create a button where user can rollover and the intro keeps on looping.

Intro is not frame base its coded running on counter
I want write some code on the button that when the mouse rollover it calls the intro function and when the intro is over then again that function is called and intro starts again and it keeps on looping. Kind of a screen saver.

Thanks

For Loop To Function
hey everyone,
I am struggling with this one:

Code:

ActionScript Code:
for (b; b<=sl; b++) {
        function analyzeAudio()  {
                if (musicPosRound == _xml.firstChild.childNodes[0].childNodes[b].attributes.audiokey) {
                        img_shell_mc.gotoAndStop(1);
                        content_mc.img_desc_txt.htmlText = _xml.firstChild.childNodes[0].childNodes[b].firstChild.nodeValue;
                        img_shell_mc.holder_mc.loadMovie(_xml.firstChild.childNodes[0].childNodes[b].attributes.img);
                        for (z=0; z<=sl; z++) {
                                _root["b"+z+"hit"] = 0;
                                _root["b"+z+"_mc"].gotoAndStop(1);
                        }
                _root["b"+b+"hit"] = 0;
                _root["b"+b+"_mc"].gotoAndStop(1);
                }
        }
}
This function is being called on an enter frame to see if the arguments are being met. I know this is not right, can someone please guide me in the right direction. I am trying to run this for loop to build out the function.
Thanks,
Derek

Loop Function
Is there any way to do this code with less lines - with usage of WHILE or FOR or some other LOOP function.

progBar1._xscale=0;
progBar2._xscale=0;
progBar3._xscale=0;
progBar4._xscale=0;
progBar5._xscale=0;
progBar6._xscale=0;
progBar7._xscale=0;
progBar8._xscale=0;
progBar9._xscale=0;
progBar10._xscale=0;

All there is changing is progbar number in name.
Any ideas?

Loop Function Help?
Hey Again,
I'm dealing with this bit of code that loads images via XML. I'm trying to write a loop function, but I need help. If this post is too long, let me know and I'll post the .fla
Okay, here goes...

This is the bit of XML that defines the array:

Code:
p = 0;
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
total = xmlNode.childNodes.length;
for (i=p; i<total; i++) {
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
}
firstImage();
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("backgrounds.xml");
This is the function that loads the first image:

Code:
function firstImage() {
loadPic(image[p]);
fadingSymbol_mc.gotoAndStop(1);
}
And this is the function that loads the next image in the array:

Code:
function nextImage() {
this.onEnterFrame = function() {
if (p<(total-1)) {
fadingSymbol_mc.prevFrame();
}
if (fadingSymbol_mc._currentframe == 1) {
fadingSymbol_mc._alpha = 0;
p++;
loadPic(image[p], 1);
fadingSymbol_mc.gotoAndStop(1);
delete this.onEnterFrame;
}
};
}
It would seem that there should be another "if" statement in the "nextImage" function if I want it to loop back to the first image, right? One that says something like: if (p==(total)) then play the firstImage function. I've tried everything that I can think of, but no luck. Can anyone help me?

Function In A Loop
Hi everyone a problem that makes me nut.
Have 5 movieclips named mc_resto1, mc_resto2, etc... and have this code


PHP Code:



for(i = 0; i < 2; i++){
    eval("mc_resto"+i).onRollover = function() {
        trace(i);
    }





The thing is when i'm doing my rollover on all the mc_resto it's tracing 3 and not 0 then 1 then 2.

have also tried something like


PHP Code:



for(i = 0; i < 2; i++){
    eval("var"+i) = i;
    eval("mc_resto"+i).onRollover = function() {
        trace(eval("var"+i));
    }





but it doesnt work

Do you have any idea please?
Thanks!

Loop Function
Is there any way to do this code with less lines - with usage of WHILE or FOR or some other LOOP function.

progBar1._xscale=0;
progBar2._xscale=0;
progBar3._xscale=0;
progBar4._xscale=0;
progBar5._xscale=0;
progBar6._xscale=0;
progBar7._xscale=0;
progBar8._xscale=0;
progBar9._xscale=0;
progBar10._xscale=0;

All there is changing is progbar number in name.
Any ideas?

Loop Function Help?
Hey Again,
I'm dealing with this bit of code that loads images via XML. I'm trying to write a loop function, but I need help. If this post is too long, let me know and I'll post the .fla
Okay, here goes...

This is the bit of XML that defines the array:

Code:
p = 0;
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
total = xmlNode.childNodes.length;
for (i=p; i<total; i++) {
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
}
firstImage();
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("backgrounds.xml");
This is the function that loads the first image:

Code:
function firstImage() {
loadPic(image[p]);
fadingSymbol_mc.gotoAndStop(1);
}
And this is the function that loads the next image in the array:

Code:
function nextImage() {
this.onEnterFrame = function() {
if (p<(total-1)) {
fadingSymbol_mc.prevFrame();
}
if (fadingSymbol_mc._currentframe == 1) {
fadingSymbol_mc._alpha = 0;
p++;
loadPic(image[p], 1);
fadingSymbol_mc.gotoAndStop(1);
delete this.onEnterFrame;
}
};
}
It would seem that there should be another "if" statement in the "nextImage" function if I want it to loop back to the first image, right? One that says something like: if (p==(total)) then play the firstImage function. I've tried everything that I can think of, but no luck. Can anyone help me?

AS2 - Loop A Function ?
hi guys i ahve this code


Code:
#include "lmc_tween.as"

customEasing = "Linear";

function regMe ()
{

mc.tween ("_alpha",20,1,customEasing);
mc.alphaTo (100,1,customEasing,4);
mc.rotateTo (360,1,customEasing,4);
mc.scaleTo (250,1,customEasing,4);
mc.scaleTo (50,0.5,customEasing,5);

}

runMe = regMe ();

for (i = 1; i < 4; i++)
{
mc = "mc" + i;
_root[mc].onEnterFrame = function ()
{
gotoAndPlay("runMe");
};
}
i have written a function and am trying to loop it ??

any ideas big thx to all who post

Function And For Loop
Hello,

ActionScript Code:
function loadWorks() {
 for (var i = 0; i<contentDoc.length; i++) {
  selectedM = _root.mc.sol_menu.contents["sub"+i];
  trace(titleArr[i]);
  selectedM.onPress = function() {
   _root.mc.content_mc.baslik_txt.text = titleArr[i];
  };
 }
}

my first trace results are:
one
two
three

although _root.mc.content_mc.baslik_txt.text = titleArr[i]; // this gives me undefined, and when I trace i, it gives me 3, which is complete nonsense.

what am I missing here, and how can I get the value of i inside of the onPress function when it is pressed, just like the way I set it on selectedM.

TIA
ilteris

Function In For Loop
I'm having some trouble making the following work in AS3. Basically I have different sets of buttons but on each set I want to be able to use a for loop to cut down on the code. Any help on the following line would be appreciated:

for (var m:int = 1; m<5; m++) {
root["m" + m + "_btn"].addEventListener(MouseEvent.CLICK, (root["m" + m + "B"]));
function (root["m" + m + "B"])(e:MouseEvent):void {
Tweener.addTween(cHM_mc, {alpha:0, time:0.5});
if (mBVal == 1) {
cHM_mc.addChild(root["mB" + m + "Loader"]);
market();
mBVal = 1;
} else if (mBVal != 1) {
cHM_mc.removeChildAt(0);
cHM_mc.addChild(root["mB" + m + "Loader"]);
market();
}
}
}

The Function is where everything is going wrong... it prompts me for an identifier and I just can't get it to work.

~ Ryan

Loop A Function Command
function Follow (){
mouse_y = _ymouse;
mouse_x = _xmouse;
setProperty (_root.move, _y, mouse_y+((getProperty(_root.move, _y)-mouse_y)/1.08));
setProperty (_root.move, _x, mouse_x+((getProperty(_root.move, _x)-mouse_x)/1.08));
setProperty (_root.figure, _y, mouse_y+((getProperty(_root.figure, _y)-mouse_y)/1.04));
setProperty (_root.figure, _x, mouse_x+((getProperty(_root.figure, _x)-mouse_x)/1.04));
}

This is a function thet I need to loop..how do you loop a function...as you can't go to the next frame?

It's has to be a function......

How Can I Stop The Loop Function?
When I'm in the Publish Settings window, I'm making sure the loop button in the HTML section is not checked, yet my movie still loops after I publish.

Where am I screwing up?

jon

For Loop In A Function Is Not Working HELP
Hi,

I have a preloader scene. This scene preloads and also loads my ASP page that contains variables like baseURLs, etc. I load my asp file and then run a function. The function stores these global variables. My problem comes in when I get to the for loop in the function. The for loop does not execute. I'm positive that the reason is that the variable _root.sliderFileTotal has not been loaded from the ASP file yet. Instead the for loop runs first and cannot get the value of _root.sliderFileTotal .

I know this because I've traced _root.sliderFileTotal outside of the for loop and I get the value. But in the for loop it does not trace. I'm sure that the for loop is taking precedence in the function and is running first.

Can anyone help me with this. I've been stuck on this the entire day. Also, I don't want to take the for loop out of the function. Everything else works fine in this function so I don't really want to drastically modify all this code because my deadline is breathing down my neck.

Thank you for your help (and even reading this far).

frame1:

Code:
var fileNames = new LoadVars();
fileNames.load("Flash/getFileNames.asp");
frame2:

Code:
fileNames.onLoad = function(success) {
if (success) {
// set the baseURL global variables + get the filenames to be loaded
_root.bottomURL = fileNames.bottomURL;
_root.baseURL = fileNames.baseURL;
_root.baseXMLURL = fileNames.baseXMLURL;
_root.billBoardFile = fileNames.billBoardFile;
_root.cube1File = fileNames.cube1File;
_root.cube2File = fileNames.cube2File;
_root.cube3File = fileNames.cube3File;
_root.cube4File = fileNames.cube4File;
_root.cube5File = fileNames.cube5File;
_root.cube6File = fileNames.cube6File;
_root.cube7File = fileNames.cube7File;
_root.cube8File = fileNames.cube8File;
_root.cube9File = fileNames.cube9File;
_root.comboBoxFile = fileNames.comboBoxFile;
_root.competitionBoardFile = fileNames.competitionBoardFile;

_root.sliderFileTotal = fileNames.sliderFileTotal;
for(n=1;n<_root.sliderFileTotal+1;n++) {
_root["slider"+n+"file"] = fileNames["slider"+n+"File"];
trace(n); // here's my problem. n does not trace. it's not hitting the for loop
}

}
}

if (fileNames.loaded && _framesloaded >= _totalframes) {
gotoAndStop ("Scene 1", 1);
} else {
var loadedbytes = getBytesLoaded();
var totalbytes = getBytesTotal();
var frame = int(loadedbytes/(totalbytes/100));
loader.gotoAndStop(frame);
}
frame3:

Code:
gotoAndPlay(2);

Function Inside A Loop
Hello.
I have a problem with tis loop or the function. It always outputs 16 when I click the buttons, but I want each button to output a number that is the same as the number on the movieclip.

for(i=1;i<=15;i++){
duplicateMovieClip(movie_mc, "movie"+i+"_mc",i);
_root["movie"+i+"_mc"]._x = -200 + 100*i;
_root["movie"+i+"_mc"]._y = 0;

_root["movie"+i+"_mc"].button_btn.onRelease = function(){
trace (i);
}

}


Please help me!

Loop And Function Question
Hello everyone, I have code below that essentially edits a specific variable called "this.ratio" to a certain value which subsequently changes the xscale of a button known as mc. I have a movie clip called assigned to mcOut that I would like have gotoAndPlay(2); I know that there is a fundamental flaw in logic with the way that I have the code presented below. I know that I have to refer to mcOut as "this" but I seem to be having difficulty getting this to work. Any help would be tremendously appreciated. Thanks in advance.
Don Ho

for (i=0; i<6; i++){
mc=this["ring"+i];
mcOut=this["outer"+i];


mc.onRollOver=function(){
this.ratio=_root.increaser;
}
mc.onRollOut=function(){
this.ratio=_root.decreaser;
mcOut.gotoAndPlay(2);

}



}

Loop Question- Doing The Function Again And Again
hi all-
i thought it would be this simple, but i want this function to work for each element in the array. However, my code only works for the first....how can i get it to work for the other three?


Code:
var aMenu:Array = ["About", "Images", "Journal", "Projects"];
makeMenuBox();
function makeMenuBox() {
var nextY = 0;
var em:MovieClip = this.createEmptyMovieClip("em", this.getNextHighestDepth());
em._x = 10;
for (i=0; i<aMenu.length; i++) {
makeButton(i)
}
}
function makeButton(id){
var letterX:Number=0;
var word:String=aMenu[id];
trace(word)
//outputs= About
}

OnEnterFrame = Function() [with Loop]
ok im trying to give a funtion to the following MC's lwall1, lwall2, lwall3 ....ect

(also rwall1, ...ect) and here is the script im using to give them all the function


PHP Code:



 onClipEvent(load) {
    for (i=1;i<=50;i++) {
        this["lwall"+i].onEnterFrame = function () {
            if (this.hitTest(_root.main.lefthit)) {
        _root.main.mleft = 0;
        cclear = 1;
    }
    if (!this.hitTest(_root.main.lefthit) && cclear == 1) {
        _root.main.mleft = 1;
        cclear = 0;
    }
        }
    }
    for (i=1;i<=50;i++) {
        _root.level["rwall"+i].onEnterFrame = function() {
            if (this.hitTest(_root.main.righthit)) {
        _root.main.mright = 0;
        cclear = 1;
    }
    if (!this.hitTest(_root.main.righthit) && cclear == 1) {
        _root.main.mright = 1;
        cclear = 0;
    }

        }
    }
}




When i looked at the Debug mode, instead of giving each movieclip the function it should, it sets a variable inside the MC called onEnterFrame, and then the rest of the code is just lost i guess o.0

Moving A Mc Function Loop
Hey I want to have a function run when I drop a mc. Like how onEnterFrame works with looping the function. I would like it to run this code in a loop.


PHP Code:



this._x += 7;
if(this._x > 633){
this._x = -33;




This is my current code, b is a button. Any help on improving my code would be awesome too As I can't figure out how to make it do something onPress without making the function seperate, such as dropper.


PHP Code:



icon=["Lucida", "Pig"]
for (i=0; i<icon.length; i++) {
    a=_root.attachMovie("b", icon[i], 100+i)
    a._x = 540
    a._y = 20+(30*i)
    a.monster.text = a._name
    a.onPress = create
}
    

function create() {
    drop = false
    a = _root.attachMovie(this._name, this._name+tm, _root.getNextHighestDepth(), {_y:_ymouse, _x:_xmouse})
    tm = tm+1
    a.onEnterFrame = mover
}

function mover() {
    if (drop == false && this._name == "Lucida"+(tm - 1) || drop == false && this._name == "Pig"+(tm - 1)) {
    this._x = _xmouse
    this._y = _ymouse
    this.onPress = dropper
    }
}

function dropper() {
    drop = true
}




Cheers in advance

Rewind Loop Function?
I've currently got an a function set that when a button is clicked the movie clip it is targeting rewinds back to the beginning. My question is when that MC reaches frame 1, how can I tell it to gotoAndPlay back to the last frame in the clip and keep rewinding? Here's my code for the button.

downArrow.addEventListener (MouseEvent.MOUSE_DOWN, downArrowDown);
downArrow.addEventListener (MouseEvent.MOUSE_UP, downArrowUp);

function downArrowDown (e:MouseEvent):void
{
scroller_mc.addEventListener (Event.ENTER_FRAME,downFrameUp);
}
function downArrowUp (e:MouseEvent):void
{
scroller_mc.removeEventListener (Event.ENTER_FRAME,downFrameUp);
}
function downFrameUp (e:Event):void
{
e.currentTarget.gotoAndStop(scroller_mc.currentFra me - 1);
}

Function Inside Loop
Hi,
I must be doing someting fundamentally wrong but here's my code for calling a function outside of another function.
The problem is that I can't access the i variable in the loop that the function is in. I keep getting the error: TypeError: Error #1010: A term is undefined and has no properties. at MethodInfo-277()


PHP Code:



// function I try to call and pass argument to
function load_db_content(req):void{
    trace("url: "+req);
    content_bg_mc.visible = true;
    var my_request:URLRequest = new URLRequest(req);
    var loader:URLLoader = new URLLoader();
    var s_vars:URLVariables = new URLVariables();
    s_vars.eng = lang;
    my_request.data = s_vars;
    //my_request.method = URLRequestMethod.GET;
    loader.dataFormat = URLLoaderDataFormat.TEXT;
    loader.addEventListener(Event.COMPLETE, load_complete);
    loader.load(my_request);
    function load_complete(e:Event):void{
        var loader:URLLoader = URLLoader(e.target);
        content_txt.htmlText = loader.data;
        content_txt.visible = true;
        my_scrollbar.visible = true;
        my_scrollbar.update();
    }
}

function set_menu():void{
    // loop through menu items
    for (var i=0; i <= 5; i++){
        // i variable is referencing a multidimensional array, works fine here
        this["bg"+[i]].title_txt.textColor = menu_array[i][2];
        // single item
        this["bg"+[i]].item_btn.addEventListener(MouseEvent.CLICK, temp);
        // archive
        this["bg"+[i]].archive_btn.addEventListener(MouseEvent.CLICK, temp_a);
        // temporary functions because I can't pass an argument from inside an event listener
        function temp(e:MouseEvent):void{
            // call content loader
        }
        function temp_a(e:MouseEvent):void{
            // here I try to use the i variable but that's not possible from inside this function
            trace("param: "+menu_array[i][3]);
            //load_db_content(menu_array[i][3]);
            
        }
}




My question is: how can I get the value of the i variable inside the temp_a function? Maybe there is another/better way to do what I'm trying to do?

Hope someone can help. Thank you very much for your time.

For Loop To Define A Function?
im trying to achieve this but in a for loop...


ActionScript Code:
myButton_1.onRollOver = function()
{
    icons.changeIcon(1);
}
myButton_2.onRollOver = function()
{
    icons.changeIcon(2);
}
myButton_3.onRollOver = function()
{
    icons.changeIcon(3);
}
myButton_4.onRollOver = function()
{
    icons.changeIcon(4);
}
myButton_5.onRollOver = function()
{
    icons.changeIcon(5);
}
myButton_6.onRollOver = function()
{
    icons.changeIcon(6);
}
myButton_7.onRollOver = function()
{
    icons.changeIcon(7);
}

i came up with this...


ActionScript Code:
for(var i:Number=1; i<8; i++)
{
    _root["myButton_"+i].onRollOver = function()
    {
        icons.changeIcon(i);
    }
}

the onRollOver event worked, BUT it looks like they all use the LAST value of i, so they all do

icons.changeIcon(7);

instead of what i was when that function was created...

how do i fix this?

Loop To Set Function To Buttons
Hello, im having some trouble with these buttons. Whenever i run it, when i trace the variable in stopThis, it alwasy comes up with 25, no matter which button i press. Any ideas on how i could do this differently? Or what the problem with my code is.


ActionScript Code:
for (var i = 0; i<=25; i++) {
    _root["symbolName"+i].onPress = function() {
        startDrag(this, true);
    }
    _root["symbolName"+i].onRelease = function() {
        stopDrag();
        _root.stopThis(i);
    };
}

How Do You Stop A Function Loop?
I'm creating a preloader that loops through an array of adjectives and then stops randomly on one of the words in the array. My code actually works, but, I also receive a "256 levels of recursion" error message in the Output dialog. That's not so great. I wonder if anyone knows of a better way to code this. (Note: I'm working in MX 2004.)

Code:
loadArray = new Array("vivid", "effervescent", "luminous", "powerful", "concise", "spontaneous", "mischievous", "radiant");
formatText = new TextFormat();
formatText.font = "Interstate-Regular";
formatText.size = 18;
formatText.color = "0xFFFFFF";
formatText.embedFonts = true;
formatText.selectable = false;
preload_txt.text = loadArray[0];
// Load first item in array
var elapsedSeconds:Number;
var n:Number = 0;
var nCount:Number = 0;
function loopText() {
if (n<loadArray.length-1) {
n++;
} else {
n = 0;
}
preload_txt.text = loadArray[n];
preload_txt.autoSize = "right";
preload_txt.setTextFormat(formatText);
nCount++; // Let nCount reach 8 plus a random number between 1 and 7
if (nCount>8+(Math.floor(Math.random()* 7 + 1))) {
delete this.loopText();
}
}
function initLoop() {
countInt = setInterval(this, "loopText", 100);
}
initLoop();
stop();

My For Loop Loses Its Value In A Function, Why?
Why does the top trace get the loop iteration of the value, but the trace below it always returns the same value?
My first value allows you to rollOver any of the properly named MCs onScreen. The rollOver should trace the value of whatever MC I am on, but it doesn't, it always returns the first one, Why?



ActionScript Code:
thisGMC = this
for (var o in thisGMC) {//Find all dropMenus in thisGMC
    if (typeof (thisGMC[o]) == "movieclip" && thisGMC[o]._name.indexOf("ddM_") != -1) {
        thisDDM = thisGMC[o];
        trace(thisDDM);
thisDDM.onRollOver=function(){
                trace(thisDDM);
}
    }}


top trace:
_level0.ddM_5
_level0.ddM_4
_level0.ddM_3
_level0.ddM_2
_level0.ddM_1
_level0.ddM_0

bottom trace:
_level0.ddM_0

I know I could just trace(this) to get it, I want to understand why the loop doesn't return it onRollover. If I am using that iteration of the value to set off the rollOver, shouldn't it return the same iteration of it in the trace?

For Loop/ Delete Function
Hey everyone,
I was wondering if someone could help me out with the for loop along with the delete function. What I am making will have 20 treasure chests on the stage (they all come from the same instance in the library so they all have the exact same code) each numbered numerically (eg: mc1, mc2, mc3) and when a user clicks on one it will pop open and then all the other ones will become unclickable. Im trying to do this by using a for loop and while a number is under 20 it makes a variable starting at mc1 and then moves onto mc2. But before it moves onto mc2 it has a delete function that deletes an onRelease. My for loop is working fine I can trace out mc1 all the way to mc20 but i cant seem to get "control" of the movieclips to delete their onRelease functions.

Here is my code that is in the move clip and sorry for the long winded explanation. If Anyone knows what I'm doing wrong or a smarter way to do this I would love to hear it. Thanks alot.

stop();
chestNum = 0;
finalNum = 0;
this.onRelease = function(){
this.gotoAndStop(2);
var sum:Number = 0;
for (var i:Number = 1; i <= 20; i++) {
sum += i;
chestNum += 1;
finalNum="mc"+chestNum
trace(finalNum)
delete _root.finalNum.onRelease;
}
}

Calling Function In While Loop
Hi!

I'm trying to create a flash chart generator. I managed to dynamically create bars linked to an array. Now I want to add a delay to their creation. I'm trying to do with a while loop but I can't seem to call my function telop() which should do the counting with delay (setInterval). I'll show you what I mean:

ActionScript Code:
import mx.transitions.Tween;
import mx.transitions.easing.*;
import classes.*;
//Array aanmaken

var waarden = new Array();
waarden[0] = 220;
waarden[1] = 500;
waarden[2] = 2000;
waarden[3] = 1500;
waarden[4] = 1200;
waarden[5] = 1150;
waarden[6] = 780;

//Hoogste en laagste waarde zoeken
maxValue = function(array){
    max = array[0];
    for (i=0; i<array.length; i++){
        if (array[i]>max){
            max = array[i];
        }
    }
    return max;
};

minValue = function(array){
    min = array[0];
    for (i=0; i<array.length; i++){
        if (array[i]<min){
            min = array[i];
        }
    }
    return min;
};
maximumwaarde = maxValue(waarden);
minimumwaarde = minValue(waarden);

var arrayProcent = new Array();

for (i=0;i<waarden.length;i++){

    arrayProcent[i] = waarden[i] * (200 / maximumwaarde);
   
}


//trace(arrayProcent[2]);

//Lijn tekenen
this.createEmptyMovieClip("lijn", this.getNextHighestDepth());
lijn.beginFill(0xCED638, 100);
lijn.moveTo (0,300);
lijn.lineTo (550,300);
lijn.lineTo (550,301);
lijn.lineTo (0,301);
lijn.endFill();



//Balken tekenen ==> critical part, how can I delay the draw loop??

//for (iteller=0; iteller< arrayProcent.length; telop()){ ==>doesn't work even with telop() above
tweener = function() {var iteller = 0;
    telop = new function() {
        trace("telop="+iteller);
        clearInterval(telinterval);
        if (iteller < arrayProcent.length){
            iteller++;
            return iteller;
            };
        //iteller++;
    }
    while (iteller < arrayProcent.length){
        telinterval = setInterval(telop(),1000);
        var spacing = 20;
        var beginX = 10 + (spacing * iteller);
        var beginY = 400;
        var eindX = 20 + (spacing * iteller);
        var eindY = 50;
        var alpha = 100;
        this["test"+iteller] = this.createEmptyMovieClip("rechthoek"+iteller, this.getNextHighestDepth());trace(this["test"+iteller]);
        this["test"+iteller].beginFill(0xCED638, alpha);
        this["test"+iteller].moveTo(beginX, 300);
        this["test"+iteller].lineTo(eindX, 300 );
        this["test"+iteller].lineTo(eindX, 300 - arrayProcent[iteller]);
        this["test"+iteller].lineTo(beginX, 300 - arrayProcent[iteller]);
        this["test"+iteller].endFill();
        //Tweening met masker
        this["rechthoek"+iteller].duplicateMovieClip("masker"+iteller,this.getNextHighestDepth());
        this["rechthoek"+iteller].setMask(this["masker"+iteller]);
        this["masker"+iteller]._alpha = 100;
        this["rechthoek"+iteller]._alpha =100 ;
        //var TweenXscale:Object = new Tween(this["masker"+iteller],"_xscale", None.easeNone, 0,100,75);
        //var TweenYscale:Object = new Tween(this["masker"+iteller],"_yscale", None.easeNone, 0,100,15);
        //if (iteller < arrayProcent.length){telop();} 
        trace(arrayProcent.length);
        trace("iteller="+iteller);
        telop();
       
       
    }
}
tweener();

While Loop Hangs In Function
Hi all
after been struggling too long with this I would like your advice.
I am preparing a sound application (virtual drum machine). So each x milliseconds, a number of sounds will be triggered.
I first wanted to use the interval to program the time between the steps but the application became too slow. Now I just the Date class and calculate the time using the Date class functions.
To check if a certain time has passed before the next series of sounds will be triggered I programmed a while loop.
But there it hangs and I don't see why.

Toffset = 60;

calcTimeInt = function () {
//function that returns a timing value
timeMin=myDate.getMinutes();
timeS=myDate.getSeconds();
timeMs=myDate.getMilliseconds();
tTime=((timeMin*60000)+(timeS*1000)+(timeMs));
return tTime;
};


runningSeq = function (runStatus) {
tTime1 = calcTimeInt();
trace("start Time is "+tTime1);
trace ("runStatus for loop " +runStatus);

for (i=0; ((i<16) && (runStatus == true)); i++) {
// first ask for current time
// update colorLED
var LEDcolorcurrent:Color = new Color(_root["LED"+(i+1)+"_mc"]);
LEDcolorcurrent.setRGB(0x00FF33);
var LEDcolorold:Color = new Color(_root["LED"+i+"_mc"]);
LEDcolorold.setRGB(0xFFFFFF);
//_root["LED"+i+"_mc"].setRGB(0x000000);
//

if ((soundArBass[i]==1)) {
trace(i);
trace("array value Bass is "+soundArBass[i]);
// trace(soundArBass[i]);
bassrun_Sound.attachSound("BD1");
bassrun_Sound.start(0,1);
// tst=myDate.getMilliseconds();
// trace("BAss " + tst);
}
if ((soundArSnare[i]==1)) {
trace(i);
trace("array value Snare is "+soundArSnare[i]);
// trace(soundSnareBass[i]);
snarerun_Sound.attachSound("SN1");
snarerun_Sound.start(0,1);
}
// end if else
if ((soundArHats[i]==1)) {
trace(i);
trace("array value Hat is "+soundArHats[i]);
// trace(soundSnareBass[i]);
hatsrun_Sound.attachSound("CH1");
hatsrun_Sound.start(0,1);
}

tTimeE = calcTimeInt();
while ((tTimeE-tTime1)<Toffset) {
//update time
tTimeE = calcTimeInt(0);
}

}

};

runningSeq(runStatus);

Why Can't My Function Within A For-loop See My I:Number
I recreated my problem in a simple form here...


Code:
for (var i:Number = 1; i<=5; i++) {

onMouseMove = function ():Void {
trace(i);
};
}
that trace isn't iterating 1 to five when the mouse moves like I want, but instead '6'.

Now in this simple example I know I could put the for-loop inside an OnMouseMove function but my actual problem relates to a larger code where I put a function inside a for-loop that I'd like to get to work.

Thanks

Sleep Function Within A For Loop
I would like each iteration of my loop to pause for 500 milliseconds before incrementing. I have a collection of movie clips that I want to be visible for half a second before becoming invisible and alpha zero again. I have tried various things including setInterval but can't quite get what I want.

onClipEvent (load) {
for (i=1; i<29; i++) {
this["spt"+i]._alpha = 80;
this["spt"+i]._visible = true;
function HideZone():Void{
//I want a half second pause here
this["spt"+i]._alpha = 0;
this["spt"+i]._visible = false;
if (i<29) clearInterval (inter)
}
inter = setInterval (HideZone, 1000);
}
}

Calling Function From Loop
My canon only shoots one ball, that is I only see 1 ball moving while the other 4 stay static, what is wrong?

ActionScript Code:
for (var i:Number=0;i<5;i++){
  var ball.Ball = new Ball();
  ball.x = 50;
  ball.y = 50;
  ball.name = "ball_" + i;
  addChild(ball);
 addEventListener(Event.ENTER_FRAME, onEnterFrame);
}

function onEnterFrame(event:Event):void{
  ball.x++;
  ball.y--;
}

Calling A Function From Within A For Loop.
This is my first post.
I am working on a game of Brickout.
I have 36 bricks and a function for making the ball bounce off of them when it hits them.

It works fine if I call the function for each brick like this:
bounceOffThis(brick1,ball,"Horz",8);
bounceOffThis(brick2,ball,"Horz",8);
bounceOffThis(brick3,ball,"Horz",8);
etc...

but I am trying to do it in fewer lines of code using a for statement like this:

numOfBricks = 36;
for (i = 1; i <= numOfBricks; i++) {
bounceOffThis(brick[i],ball,"Horz",8);
}

I am trying to figure out why it's not working. If anyone has any suggestions I would really appreciate it.

Calling Function Within A Loop
I'm about to shoot my brains out!! After finally getting my loop to work I can't get the function I've predefined to work in the loop.

I have a function that assigns values to each "button". Each button is the name of an audio file. The function has variables that when the button is pressed it either enables or disables certain buttons. I actually set the loop up 2 ways, maybe you can tell me if one way is better than the other, but either way I can't get the function to work. It just holds the last value in the loop...

Here's way#1:

ActionScript Code:
function mssgs() {
 var i;
 for (i=0; i < this.n; i++) {
//attach movie
_root.content.cnt.attachMovie("empty", "tag"+i, i);
_root.content.cnt["tag"+i]._x=10;
_root.content.cnt["tag"+i]._y=111+(i*20);
_root.content.cnt["tag"+i].titleM = this["show"+i] + " - " + this["title"+i];

_root.content.cnt["tag"+i].onPress = messages(this["href"+i],this["mp3"+i],this["notes"+i],43+(20*i));
 }

Here's method#2:

ActionScript Code:
function mssgs() {
 var i;
 for (i=0; i < this.n; i++) {
//attach movie
doug=_root.content.cnt.attachMovie("empty", "tag"+i, i);
doug._x=10;
doug._y=111+(i*20);
doug.titleM = this["show"+i] + " - " + this["title"+i];
doug.onPress = messages(this["href"+i],this["mp3"+i],this["notes"+i],43+(20*i));
 }
}

Either way it's this that I'm having problems with:

ActionScript Code:
onPress = messages(this["href"+i],this["mp3"+i],this["notes"+i],43+(20*i));

It only holds the last values that were passed, no matter which button I press.

I've have been through ALL the forums. Any help would be VERY appreciated!! Thanks

For Loop Isn't Working In Function?
Hi,
I've got the following code:

the problem is, when I run the while loop, everything is working fine. (The for loop is "disabled") But when i use the for loop with the same code... nothing happens!

Does anyone knows what i'm missing? I am quite a newbie in flash... :s


ActionScript Code:
heightSpace = 80;

// while loop counter
count = 0;

while (count<7)
{
    count += 1;
    var mcGreatWith = this.mcGreatWith1.duplicateMovieClip("gw_boxx"+count, count);
   
    mcGreatWith._y = (heightSpace * count);
}

/* ************************ other part *************************** */

//Get XML
greatWithXML = new XML();

greatWithXML.load("getProduct.php?id=80205");
greatWithXML.ignoreWhite=true;

// If XML is loaded
greatWithXML.onLoad = function(success)
{
    if (success)
    {         
        _global.numberItems = greatWithXML.firstChild.childNodes.length;           
       
        for(i=0; i<greatWithXML.firstChild.childNodes.length; i++)
        {   
            trace(i + " ... is working fine...");
            
    var mcGreatWith = this.mcGreatWith1.duplicateMovieClip("gw_boxx"+i, i);
   
    mcGreatWith._y = (heightSpace * i);   
        }
    }   
}

Dynamic Function In For Loop...Possible?
Just like it says. I've made a Biology Dictionary that uses an array to access the necessary information to display. From there I made a movieclip which contains more movieclips that act as buttons for displaying the information.

Now from there I realized that I would have to do something like

ActionScript Code:
_root.scroller.scroll0_mc.onRelease=new function(){
_root.descrip_txt.text=_root.descriptions[0];
for each and every buttons code. Now I could do that, but I don't want to have to write that same code again and again with only minor alterations (Yes I know of Ctrl+C and Ctrl+V)

So is there any way I could automate that bit of code via a for loop?

Thanks in advance.

Function Inside For Loop
I'm having problems with my code and I'm thinking that maybe it is sth to do with the way functions work or do not work when put inside a for loop.

I'm looping through xml data and for every link node I'm making a button and attaching an onRelease action. But for some reason the last link is added to every button. I mean its making the buttons fine except for every button opens the same url which is the url of the last button in the list.


ActionScript Code:
for(var i = 0; i < rootNode.firstChild.childNodes.length; i++) {
    var theURL = rootNode.firstChild.childNodes[i].attributes.url;
    var Display = rootNode.firstChild.childNodes[i].attributes.displayName;
    var item_mc = _root.menu_mc.attachMovie("menu_item","item"+i, i);
    item_mc._y = i * item_spacing;
    item_mc.url_txt.text = Display;
    item_mc.main_btn.onRelease = function()
            {
            getURL(theURL, "floater");
            }
    }

Function Inside Loop
I'm trying to assign onRelease functions to a set of 17 buttons using a loop. The actionscript I have at the moment looks like:


ActionScript Code:
for (y=0; y<18; y++) {
       gui_news["gui_news_entry_butt_"+y].onRelease = function() {
        _root.curr_title = _root.flashData_lv["title"+y];
        _root.curr_date = _root.flashData_lv["date"+y];
        _root.curr_entry = _root.flashData_lv["entry"+y];
        _root.entry_select();
    };
}

When I try to do this in the above loop, nothing happens. It works fine if I declare the function outside a loop and increment the numbers manually (For example:


ActionScript Code:
gui_news.gui_news_entry_butt_0.onRelease = function() {
    _root.curr_title = _root.flashData_lv.title0;
    _root.curr_date = _root.flashData_lv.date0;
    _root.curr_entry = _root.flashData_lv.entry0;
    _root.entry_select();
};

My question is, is it possible to declare functions inside loops, and if so, what is the syntax for it?

Declaring Function In A Loop
hi every1
can some1 pls find a way to this problem
>>>>>>>>>>>>>>
for (var i = 1; i<16; i++) {
this.example_pannel["button_"+i].Mainbutton.onRelease = function() {
trace("this is button >> "+i);
};
}

>>>>>>>>>>>>>>>>>>
in the above movie i have 16 movies named button_1 , button_2 , button_3
which have a button in them called Mainbutton.

i want to setup a onRelease function for all of them with a loop. the aim isd to grab url from the xml sheet and asign onrelase function on theese buttons.

problem with the script is that whe i click the above abittons the ( i ) in the loop is a common variable and shares the value with all the buttns and the result is all the buttons trace the same value when clicked, which 16 (the final value of i when the loop is finished.)

any solution to this problem ??
thank in advance.

Event Function Within A Loop
I am trying to get an onEnterFrame function to work within a loop, passing values from an array to run and stop dynamically attached movies at corresponding frames. The onEnterFrame function in the loop doesn't know what "i" is, or the array that I am referencing. Any help would be appreciated.







Attach Code

//create new LoadVars class
var LFdata= new LoadVars();
var names:Array=[];
var partic:Array=[];

LFdata.onLoad=function(success:Boolean):Void{
if(success){
//make arrays
names = this.name.split(",");
partic =this.partic.split(",");

//call charting function
displayChart();

}else{
trace("Couldn't read the file");
}
}

function displayChart() {
for (var i:Number=0;i<partic.length;i++){
/// //attach vertical firmName text movie
_root.attachMovie("firmName","firmName"+i, i+100, {_x:0,_y:(i+1)*30});
this["firmName"+i].firm.text = names[i];

/// //set movie bars scale and colors
var runClip = _root.attachMovie("running","running"+i,i+200,{_x:200, _y:(i+1)*30});
var pct:Number=Number(partic[i]);
runClip.onEnterFrame = function(){
var nFrame:Number = this._currentframe;
if(nFrame<pct){
this.nextFrame();
nFrame++;
}else{
this.gotoAndStop(pct);
this.husky.stop();
}

updateAfterEvent();
}

// set text fields for percents
var tFormat = new TextFormat();
tFormat.font = "Arial TUR";
tFormat.color = 0x666666;
tFormat.size=12;
tFormat.bold=true;
tFormat.align="right";
//name,depth,x,y,h,w
createTextField("pct"+i,i+300,500, (i+1)*30, 40, 20);
this["pct"+i].setNewTextFormat(tFormat);
this["pct"+i].text = partic[i]+"%";

}

}
LFdata.load("LFACdata2.txt");

Event Function Within Loop
I am trying to get an onEnterFrame function to work within a loop, accessing values from an array. However, i does not seem to be looping through the function, and the values of the array are then undefined. Any help woud be appreciated. Thanks!










Attach Code

//create new LoadVars class
var LFdata= new LoadVars();
var names:Array=[];
var partic:Array=[];

LFdata.onLoad=function(success:Boolean):Void{
if(success){
//make arrays
names = this.name.split(",");
partic =this.partic.split(",");

//call charting function
displayChart();

}else{
trace("Couldn't read the file");
}
}

function displayChart() {
for (var i:Number=0;i<partic.length;i++){
/// //attach vertical firmName text movie
_root.attachMovie("firmName","firmName"+i, i+100, {_x:0,_y:(i+1)*30});
this["firmName"+i].firm.text = names[i];

/// //set movie bars scale and colors
var runClip = _root.attachMovie("running","running"+i,i+200,{_x:200, _y:(i+1)*30});
var pct:Number=Number(partic[i]);
runClip.onEnterFrame = function(){
var nFrame:Number = this._currentframe;
if(nFrame<pct){
this.nextFrame();
nFrame++;
}else{
this.gotoAndStop(pct);
this.husky.stop();
}

updateAfterEvent();
}

// set text fields for percents
var tFormat = new TextFormat();
tFormat.font = "Arial TUR";
tFormat.color = 0x666666;
tFormat.size=12;
tFormat.bold=true;
tFormat.align="right";
//name,depth,x,y,h,w
createTextField("pct"+i,i+300,500, (i+1)*30, 40, 20);
this["pct"+i].setNewTextFormat(tFormat);
this["pct"+i].text = partic[i]+"%";

}

}
LFdata.load("LFACdata2.txt");

Loop / Function Problem
I have created a series of button with references of swfs to load which the buttons are clicked.

The click function only works for every third button. All the buttons and names are iterated correctly.
Is the problem with the line item "ProjectClicked(this._parent.projectID);" or something else?
Any help would be appreciated.

function buildResMenu(){
var xSpacing:Number = 130;
var ySpacing:Number = 20;
var xStart:Number = 0;
var yStart:Number = 0;
var count:Number = 0;
for (i=1; i<4; i++) {
for(j=0; j<3; j++) {
count++;
var name:String = "menu2" + count + "_mc";
_root.m2.attachMovie("flipper", name, count);
_root.m2[name]._x = (i * xSpacing) - 130;
_root.m2[name]._y = j * ySpacing;
_root.m2[name].main_text.text = resMenu[count-1][0];
_root.m2[name].projectID = resMenu[count-1][1];
}


_root.m2[name].item_btn.onPress = function () {
itemProjectClicked(this._parent.projectID);


}
}
}


;

buildResMenu();

function itemProjectClicked (projectID:String){
_root.m4.loadMovie(projectID);
}

[MX] Loop Function Problem
Hi. I have a function that loops inside a movieclip with 7 btns that tells what collor the last hit btn should be and what collor the rest should look like. The problem is that after I hit one btn, I cant make the object btn function as a btn, with the rollover and others btn frame properties.
Here is the function:


Code:
// define a funcao mA2click (menu A)
function mA1click() {
for (var a=1; a<8; a++) {
var btn = _root.mA1["A1"+a];
if (btn == this) {
hitColor = new Color(this);
hitColor.setRGB(0xff0000);
clickSound = new Sound(btn);
clickSound.attachSound("click");
clickSound.start(0, 3);
this.enabled = false;
} else {
normalColor = new Color(_root.mA1["A1"+a]);
normalColor.setRGB(0x333333);
_root.mA1["A1"+a].enabled = true;
_root.mA1["A1"+a].onRollOver = _root.mouseOver(this);
}
}
}
for (var a=1; a<8; a++) {
_root.mA1["A1"+a].onRelease = mA1click;
}

Copyright © 2005-08 www.BigResource.com, All rights reserved