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




Recursive Trace() Function?



I am trying to better understand what properties event objects really have because the documentation isn't entirely consistent (The ErrorEvent constructor refers to an 'id' parameter which is not mentioned in the description of the ErrorEvent.ERROR Event). I was hoping to get my hands on a good function to trace ALL of the properties of a given Event. Sadly, this one I wrote doesn't seem to work for some reason (output is empty).

code:
package {
public class JTA {
static public function traceRecursive(obj:*) {
for(var key:String in obj) {
trace(key + ":" + obj.key);
}
}
}
}



FlashKit > Flash Help > Actionscript 3.0
Posted on: 02-27-2008, 08:02 PM


View Complete Forum Thread with Replies

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

Recursive Trace Function?
I am trying to better understand what properties event objects really have because the documentation isn't entirely consistent (The ErrorEvent constructor refers to an 'id' parameter which is not mentioned in the description of the ErrorEvent.ERROR Event). I was hoping to get my hands on a good function to trace ALL of the properties of a given Event. Sadly, this one I wrote doesn't seem to work for some reason (output is empty).


ActionScript Code:
package {
    public class JTA {
        static public function traceRecursive(obj:*) {
            for(var key:String in obj) {
                trace(key + ":" + obj.key);
            }
        }
    }
}

Help With Recursive Function
hey guys!

I require the use of recursion in a function that compares clips towards finding the biggest one to orbit, the condition should be the size of the array but it's not working, recursion was always the greatest fear of my c programming education, when i spent weeks trying to create that old fibonnacci sequence with no hope,
help please! this old ghost its coming back to haunt me ...
any recursive paladins around?


Code:
// Array for Circle movieClips
var circleMcArray:Array = new Array();

// vars for Stage Boundaries
var left:Number = 0;
var top:Number = 0;
var right:Number = Stage.width;
var bottom:Number = Stage.height;

// Stage Listener
Stage.addListener(this);

onResize = function () {
right = Stage.width;
bottom = Stage.height;
};

// *------------------- GET MIC INPUT------------------*//
var mic = Microphone.get();
attachAudio(mic);
mic.setUseEchoSuppression(false);
// var micVol:Number = mic.activityLevel;

// *------------------- ENTER FRAME, CREATE CIRCLES, SET ROTATION ---------------*//

function onEnterFrame(Void):Void
{

if (mic.activityLevel>5.68)
{
mcLife = setInterval(createCircle(), 1000);
// clearInterval(mcLife);
}


}

//**--------- FUNCTION TO CREATE CIRCLES --------------**//

createCircle = function (){

var i:Number = circleMcArray.length;
var mc=this.createEmptyMovieClip("circle"+i, i);
// set radius according to activity level
r = mic.activityLevel;

// DRAW CIRCLE USING DRAWING API

var A:Number = Math.tan(22.5*Math.PI/180);
var endx:Number;
var endy:Number;
var cx:Number;
var cy:Number;

// mc.lineStyle(1, 0x000000, r);
mc.beginFill(0x000000, r);
mc.moveTo(r,0);
for (var angle = 45; angle<=360; angle += 45) {
endx = r*Math.cos(angle*Math.PI/180);
endy = r*Math.sin(angle*Math.PI/180);
cx = endx+r*A*Math.cos((angle-90)*Math.PI/180);
cy = endy+r*A*Math.sin((angle-90)*Math.PI/180);
mc.curveTo(cx, cy, endx, endy);
}
mc.endFill();
//create the onEnterFrame function for the movieclip
mc.onEnterFrame = function(){

if (this.centerMC != undefined)
{
var centerx = this.centerMC._x;
var centery = this.centerMC._y;

// increment your angle
// set the x and y of the movieclip based on sine and cosine
var speed = .5;
// trace(speed);
var newx = this.orbitingRadius * Math.sin( this.angle*Math.PI/180.0 ) + centerx;
var newy = this.orbitingRadius * Math.cos( this.angle*Math.PI/180.0 ) + centery;
// trace("newx,y " + newx + " " +newy);
// mc.lineStyle(1, 0x000000, 40);
// mc.moveTo(newx, newy);
// mc.lineTo(centerx, centery);
this.angle += speed;
// this._alpha -= speed;

if(this._alpha == 0)
{
this.clear();
trace(this);
}

this._x = newx;
this._y = newy;

// lineCenterOrbit(centerx, centery, newx, newy);
// this.moveTo(newx, newy);
// this.lineTo(centerx, centery);
// trace (this._name + " orbiting around ... " + this.centerMC._name);
}
else {
// trace(this._name + " i'm not orbiting...");
}
}
//position circle randomly within stage

var x1:Number = Math.random()*Stage.width;
var y1:Number = Math.random()*Stage.height;

mc._x = x1;
mc._y = y1;

findFriend(mc);

// each time a circle is created push into an array
circleMcArray.push(mc);
};


//**--------- FUNCTION TO FIND NEAREST MOVIECLIP --------------**//

findFriend = function(mcA:MovieClip){

// var to compare to
var closestDistanceSoFar:Number = 999;

if(circleMcArray.length == 0){
return;
}
else
{
var distance:Number;
var dx:Number;
var dy:Number;
var mcB:MovieClip;

for (var j=0; j < circleMcArray.length; j++)
{
dx = mcA._x - circleMcArray[j]._x;
dy = mcA._y - circleMcArray[j]._y;

distance = Math.sqrt(dx*dx + dy*dy);

if( distance < closestDistanceSoFar){
mcB = circleMcArray[j]; // this is our closest neighbor right now
closestDistanceSoFar = distance; //now THIS is the closest distance, which will be used the next time we compare
}
}

var sizeofA:Number = mcA._height;
var sizeofB:Number = mcB._height;

// trace( "sizeA ="+ sizeA + " sizeB = " +sizeB);

if (sizeofA < sizeofB){
// trace("sizeB is greater");
//CREATE A property on mcA's timeline to save the MC that it orbits around
mcA.centerMC = mcB;
mcA.angle = 0;
mcA.orbitingRadius = closestDistanceSoFar;
k=0;
while(k < circleMcArray.length)
{
// recursion for biggest friend to keep finding next big one on the array
findFriend(mcA);
k++;
//trace(k);
}
} else {
// trace("sizeA is greater");
mcB.centerMC = mcA;
mcB.angle = 0;
mcB.orbitingRadius = closestDistanceSoFar;
k=0;
while(k < circleMcArray.length)
{
// same if its mcB
findFriend(mcB);
k++;
// trace(k);
}
}

}
}
lineCenterOrbit = function(centerX:Number, centerY:Number, newX:Number, newY:Number)
{
for(var i=0; i< circleMcArray.length; i++){
mcLine = this.createEmptyMovieClip("line"+i, i);
mcLine.moveTo(centerX, centerY);
mcLine.onEnterFrame = function()
{
mcLine.lineStyle(1, 0x000000, 50);
mcLine.lineTo(newX, newY);
}
}

}

stop();
thanks for reading!

Recursive Function
Hello,
I do this function

function dimensioneAttuale(cerchio){//funzione ricorsiva per trovare la dimensione del cerchio
trace("chiamata");
var dimensioneAtt:Array = new Array();

if(cerchio[4] != 0){
cerchio = arrayCerchio[cerchio[4]];
dimensioneAtt = dimensionAttuale(cerchio);
trace("qui2");
}
else{
trace("qui");
dimensioneAtt[0] = arrayCerchio[cerchio[4]][1]._width;
dimensioneAtt[1] = arrayCerchio[cerchio[4]][1]._height;
}

trace("dentro: " + dimensioneAtt[0] + "," + dimensioneAtt[1]);
trace("dentro: " + cerchio[1]._width + "," + dimInizio);
dimensioneAtt[0] = cerchio[1]._width * dimensioneAtt[0] / dimInizio;
dimensioneAtt[1] = cerchio[1]._height * dimensioneAtt[1] / dimInizio;

return dimensioneAtt;
}

When I call this function and it print "qui2" but It don't recall itself (It don't reprint "chiamata".
Where is the problem?
Thanks a lot

Recursive Function
I'm very interested in how nature works. I began with flash for that very purpose. I know recursion is one of the key elements in fractal nature. But I can't seem to find any good (read:simple) examples of the use of recursive functions. Like a simple example how to grow a tree or plant or something like that.

Anybody has any good info?
thx

XML Recursive Function
Hi, I've been trying to create a recursive XML parser, and been partly succesful with it. I've already been able to parse the xml with the next code:

private function mParseXML(xmlToParse) {
for (var n in xmlToParse.childNodes) {
var tempObj:Object = new Object();
tempObj["type"] = xmlToParse.childNodes[n].nodeName;
for (var m in xmlToParse.childNodes[n].attributes) {
tempObj[m] = xmlToParse.childNodes[n].attributes[m];
}
if (xmlToParse.childNodes[n].nodeName == "menu") {
mParseXML(xmlToParse.childNodes[n]);
}
}
}

but I haven't been able to save the information in an useful way. What I'm trying to achieve is at the end have an array with the same structure of the xml and access the attibutes with dot notation for example:
trace(_xmlArray[0][2].name)
Thanks a lot for your help.
German Hernandez





























Edited: 03/01/2007 at 01:24:53 PM by germanHernandez

Recursive Function Xml
I am loading an xml and looping through it using a recursive function. The problem is that it only reads through the first tree and then quits..??

XML:

PHP Code:



<root id="0"> <dir id="1" name="Lounge,_Chillout">  <dir id="2" name="Opera_Chillout_2003">   <dir id="3" name="CD1">    <pl>1e00ad1d-66ba-4496-8168-0d926422739c.xml</pl>     <tn>15</tn>    </dir>   <dir id="4" name="CD2">    <pl>47c5dc51-e0d6-4b5e-a837-76a18600fcd6.xml</pl>     <tn>14</tn>    </dir>  </dir>  <dir id="5" name="Roger_Sanchez_-_First_Contact">   <pl>9c5eb7bf-9a0d-45e9-8e51-b2acccd66b17.xml</pl>    <tn>9</tn>   </dir>  <dir id="6" name="Royksopp_-_Melody_a.m">   <pl>7cbb66fd-2d33-427a-8627-cce502ee14b8.xml</pl>    <tn>10</tn>   </dir>  <dir id="7" name="Secret_Garden_-_Songs_from_a_Secret_Garden">   <pl>607bf25e-c1a1-4660-9b8b-0bf4731ae61a.xml</pl>    <tn>12</tn>   </dir> </dir> <dir id="8" name="Soundtracks">  <dir id="9" name="Army_Of_Darkness">   <pl>991a68ac-1be2-4201-b3ed-65d341e8134d.xml</pl>    <tn>21</tn>   </dir>  <dir id="10" name="Soundtrack_-_Reservoir_Dogs" />   </dir></root> 




Actionscript:

PHP Code:



loadXml = function (filename) {summaryXml = new XML();summaryXml.ignoreWhite = true;summaryXml.load("xmls/"+filename+".xml");summaryXml.onLoad = function(success) {if (success) {getDirs(summaryXml,6);}}; getDirs = function(xml, id){currentNodes = xml.childNodes;for (var i=0; i< currentNodes.length; i++) { if (currentNodes[i].attributes.id == id) {     trace("bingo @ " + currentNodes[i].attributes.name);     } else {     if (currentNodes[i].hasChildNodes()) {      trace("search goes on @ id: " + currentNodes[i].attributes.name);      getDirs(currentNodes[i], id)    }    else    {     trace("no more childs");    }}}}; 




the result is:

Quote:




search goes on @ id: undefined
search goes on @ id: Lounge,_Chillout
search goes on @ id: Opera_Chillout_2003
search goes on @ id: CD1
search goes on @ id: undefined
no more childs




I found a similar problem in another thread. i tried the solution from that thread but it didn't solve my problem..

Does anyone have an idea?

Is This A Recursive Function? Help Please..
Hello all,

I have a movie with 5 buttons in it. Now, when a button is rolled over, it has an on state, and when clicked, it has an inactive state. Instead of writing alot of redundant code, I'm trying to see if I can simplify it. Here is what I have:

Quote:




//active/inactive
function active (navClip) {
if (this.hitTest = true) {
navClip.onEnterFrame = function () {
this.enabled = false;
};
} else if (this.hitTest = true) {
navClip.onEnterFrame = function () {
this.enabled = true;
};
}
}
// button code
myBtn1.onRelease = function () {
active (myBtn1);
goToAndPlay some clip I have on stage
};

myBtn2.onRelease = function () {
active (myBtn2);
goToAndPlay some clip I have on stage
};




All AS is in the root, first frame. Any help would be GREATLY appreciated!!

Many Thanks in advance!

J

Is This A Recursive Function? Help Please..
Hello all,

I have a movie with 5 buttons in it. Now, when a button is rolled over, it has an on state, and when clicked, it has an inactive state. Instead of writing alot of redundant code, I'm trying to see if I can simplify it. Here is what I have:

Quote:





//active/inactive
function active (navClip) {
if (this.hitTest = true) {
navClip.onEnterFrame = function () {
this.enabled = false;
};
} else if (this.hitTest = true) {
navClip.onEnterFrame = function () {
this.enabled = true;
};
}
}
// button code
myBtn1.onRelease = function () {
active (myBtn1);
goToAndPlay some clip I have on stage
};

myBtn2.onRelease = function () {
active (myBtn2);
goToAndPlay some clip I have on stage
};





All AS is in the root, first frame. Any help would be GREATLY appreciated!!

Many Thanks in advance!

J

Help With Recursive Function...
Hello all, I've been trying to make a function that creates a running total of a number variable. To explain as best I can, here goes...

1) I have 1 movieclip on the stage...clip1. Inside clip1 is clip2...inside clip2 is clip3...so they're basically nested movieclips.

2) In all of the nested movieclips, I have a variable called 'depth'. I gave each of them a value of 10 (you'll see that in the code below). On the main timeline, I just set the depth value to 0.

3) Basically what this function does, is that it checks to see if there's a variable in the movieclip called 'depth'...if there is, it adds it to the running total and continues on...if not, it returns an undefined variable and exits.

However, if there is a variable called 'depth' in the movieclip, it adds it to the running total and then the function calls itself again, with two new properties...the parent of the movieclip, and the new running total. The process repeats over and over until all parent clips of the original have been searched for the variable 'depth'. Now I have a running total.
Code:

clip1.depth = 10;
clip1.clip2.depth = 10;
clip1.clip2.clip3.depth = 10;
function depthAdd(clip:MovieClip, totalDepth:Number):Number {
   // if there is a depth variable...
   if (clip.depth != undefined) {
      // add it to the running total
      totalDepth += clip.depth;
   }
   // if there is a parent clip
   if (clip._parent != undefined) {
      // call function again with parent clip and running total
      depthAdd(clip._parent, totalDepth);
   } else {
      // return the total depth
      trace(totalDepth);
      return totalDepth;
   }
}
trace(depthAdd(clip1.clip2.clip3, 0));
The problem lies in my return statement...for some reason, it wants to return 'undefined' no matter what! totalDepth contains a correct value - I checked it in the debug panel...it's still there. However, when I do the return statement, it returns undefined...can anyone shed some light on this?

Edit - Function slightly changed in the past 5 minutes, but problem still persists...

Help Recursive Xml Function Needed
Hi there, can anyone help in building in a recursive function that will go through all the nodes in my xml file looking for a particular attribute?

thanks

frank

Recursive Function Nightmare
hi am toying with a game. there is a grid of balls. 10*10.

when a user clicks on a ball all balls of the same color in either horizontal or vertical lines must b removed (_visible =false). these ones that are removed have to also be checked on their secondary axis for balls of the same color.

i get an error in the flash ide that reads:
256 levels of recursion were exceeded in one action list.
This is probably an infinite loop.
Further execution of actions has been disabled in this movie.

fair enough a stack overflow, so my code must be wrong ...

ActionScript Code:
Board.prototype.doSomeWork = function(ballPtr){
// from what i understood from our conversation any neighbo(u)ring
//should also be checked along there x and y axis
    trace("do some work");
    trace("x:"+ ballPtr.x + " y:" + ballPtr.y);
    this.checkXaxis(ballPtr);
    ballPtr._visible = false;
    this.recurCount = 0;
};

Board.prototype.cascadeCollum = function(ballPtr){
    // when a ball gets deleted this should b called
   
};
Board.prototype.checkXaxis = function(ballPtr){
    // here there will be two loops one running left and one running right from the ball
    for (var i = ballPtr.x -1 ; i >= 0; i--)
    {   
        if(this.ballArray[i][ballPtr.y]._visible == false){break;}
        if (ballPtr.BallColor == this.ballArray[i][ballPtr.y].BallColor){break;}
        this.checkYaxis(this.ballArray[i][ballPtr.y])
        //this.ballArray[i][ballPtr.y].unloadMovie();
        this.ballArray[i][ballPtr.y]._visible=false;
   
    }
    for (var i = ballPtr.x + 1; i < this.ballArray.length;i++)
    {   
        if(this.ballArray[i][ballPtr.y]._visible == false){return;}
        if (ballPtr.BallColor == this.ballArray[i][ballPtr.y].BallColor){ return;}   
        this.checkYaxis(this.ballArray[i][ballPtr.y])
        //this.ballArray[i][ballPtr.y].unloadMovie();
        this.ballArray[i][ballPtr.y]._visible=false;
       
       
    }
    return;
   
};
Board.prototype.checkYaxis = function(ballPtr){
    // first up
    trace("check y axis");
    for (var i = ballPtr.y + 1; i < this.ballArray[ballPtr.x].length; i++)
    {   
        if (this.ballArray[ballPtr.x][i]._visible == false){break;}
        if (ballPtr.BallColor != this.ballArray[ballPtr.x][i].BallColor){break;}
        this.checkXaxis(this.ballArray[ballPtr.x][i]);
        //this.ballArray[ballPtr.x][i].unloadMovie();
        this.ballArray[ballPtr.x][i]._visible = false;
        trace("y invisible");
       
    }
    for(var i = ballPtr.y -1; i >= 0; i--)
    {
        if (this.ballArray[ballPtr.x][i]._visible == false){return;}
        if (ballPtr.BallColor == this.ballArray[ballPtr.x][i].BallColor){return;}   
        //this.checkXaxis(this.ballArray[ballPtr.x][i]);
        //this.ballArray[ballPtr.x][i].unloadMovie();
        this.ballArray[ballPtr.x][i]._visible = false;

    }
   
    return;
   
};

but all my escape code gets called...(the traces therefore...)
so what is wrong here or is this an inbuild protection?
if that is the case is there anyway to get around it?

Recursive Function, XML Tree
ok guys, im having a problem reading a xml tree in Flash MX...

i got this tree,

data.xml

PHP Code:



<menu>
    <menuitem label="menu1">
        <item label="menu1_item1" file="file.swf" />
        <item label="menu1_item2" file="file.swf" />
        <menuitem label="sub1">
            <item label="menu1_sub1_item1" file="file.swf" />
            <item label="menu1_sub1_item2" file="file.swf" />
            <item label="menu1_sub1_item3" file="file.swf" />
            <item label="menu1_sub1_item4" file="file.swf" />
        </menuitem>
    </menuitem>
    <menuitem label="menu2">
        <item label="menu2_item1" file="file.swf" />
        <item label="menu2_item2" file="file.swf" />
        <menuitem label="sub1">
            <item label="menu2_sub1_item1" file="file.swf" />
            <item label="menu2_sub1_item2" file="file.swf" />
            <item label="menu2_sub1_item3" file="file.swf" />
            <item label="menu2_sub1_item4" file="file.swf" />
        </menuitem>
    </menuitem>
    <menuitem label="menu3">
        <item label="menu3_item1" file="file.swf" />
        <item label="menu3_item2" file="file.swf" />
        <menuitem label="sub1">
            <item label="menu3_sub1_item1" file="file.swf" />
            <item label="menu3_sub1_item2" file="file.swf" />
            <item label="menu3_sub1_item3" file="file.swf" />
            <item label="menu3_sub1_item4" file="file.swf" />
        </menuitem>
    </menuitem>
</menu> 




and this Actionscript to just to view the tree...


PHP Code:



function addChilds(childs) {
    for (i=0; i<childs.length; i++) {
        if (childs[i].hasChildNodes()) {
            addChilds(childs[i].childNodes);
        } else {
            trace(childs[i].attributes.label);
        }
    }
}
myXML = new XML();
myXML.ignoreWhite = true;
myXML.load("data.xml");
myXML.onLoad = function() {
    addChilds(this.firstChild.childNodes);
}; 




now comes the problem, when running it, i only get this:


Quote:




menu1_item1
menu1_item2
menu1_sub1_item1
menu1_sub1_item2
menu1_sub1_item3
menu1_sub1_item4




meaning that when it calls itself again, that it will stop searching the next items on the same level from where it was called...

how do i not let it stop searching and complete the tree.... please help..

(i hope it maked any sence)

Recursive Function With Return Value
How can I have a recursive function that also returns a value. Here's an example.


Code:
public function getNine():Number{

var num:Number;

var myArray:Array = new Array(1,2,3,4,5,6,7,8,9);

if(myArray[0] != 9){
myArray.slice(1);
getNine();
}

return num;
}

var needNine:Number = getNine();

Recursive Function, XML Tree
ok guys, im having a problem reading a xml tree in Flash MX...

i got this tree,

data.xml

PHP Code:



<menu>
    <menuitem label="menu1">
        <item label="menu1_item1" file="file.swf" />
        <item label="menu1_item2" file="file.swf" />
        <menuitem label="sub1">
            <item label="menu1_sub1_item1" file="file.swf" />
            <item label="menu1_sub1_item2" file="file.swf" />
            <item label="menu1_sub1_item3" file="file.swf" />
            <item label="menu1_sub1_item4" file="file.swf" />
        </menuitem>
    </menuitem>
    <menuitem label="menu2">
        <item label="menu2_item1" file="file.swf" />
        <item label="menu2_item2" file="file.swf" />
        <menuitem label="sub1">
            <item label="menu2_sub1_item1" file="file.swf" />
            <item label="menu2_sub1_item2" file="file.swf" />
            <item label="menu2_sub1_item3" file="file.swf" />
            <item label="menu2_sub1_item4" file="file.swf" />
        </menuitem>
    </menuitem>
    <menuitem label="menu3">
        <item label="menu3_item1" file="file.swf" />
        <item label="menu3_item2" file="file.swf" />
        <menuitem label="sub1">
            <item label="menu3_sub1_item1" file="file.swf" />
            <item label="menu3_sub1_item2" file="file.swf" />
            <item label="menu3_sub1_item3" file="file.swf" />
            <item label="menu3_sub1_item4" file="file.swf" />
        </menuitem>
    </menuitem>
</menu> 




and this Actionscript to just to view the tree...


PHP Code:



function addChilds(childs) {
    for (i=0; i<childs.length; i++) {
        if (childs[i].hasChildNodes()) {
            addChilds(childs[i].childNodes);
        } else {
            trace(childs[i].attributes.label);
        }
    }
}
myXML = new XML();
myXML.ignoreWhite = true;
myXML.load("data.xml");
myXML.onLoad = function() {
    addChilds(this.firstChild.childNodes);
}; 




now comes the problem, when running it, i only get this:


Quote:




menu1_item1
menu1_item2
menu1_sub1_item1
menu1_sub1_item2
menu1_sub1_item3
menu1_sub1_item4




meaning that when it calls itself again, that it will stop searching the next items on the same level from where it was called...

how do i not let it stop searching and complete the tree.... please help..

(i hope it maked any sence)

Recursive Function With SetInterval
Last edited by cdMan : 2002-08-12 at 22:13.

























why don't work??


Code:
fun = function () {
trace(getTimer()/1000);
setInterval(arguments.callee, 1000);
};
fun();
some idea?

[F8] Scope Of Variables In Recursive Function
Cant seem to figure this one out. Ive got a recursive function call but the variables in it arent staying local. When it returns from a call to the addToStruct, cur doesnt have the same value as it had before the function call.

code: function addToStruct(pnt, xmlnode) {
var cur = xmlnode.firstChild;
for (i=0; i<xmlnode.childNodes.length; i++) {
// Stuff...
if (cur.childNodes.length>0) {
addToStruct(tmp, cur);
}
cur = cur.nextSibling;
}
}

Local Variable In Recursive Function
I'm trying to create a recursive function to parse a piece of XML, but when it runs it recurses before it finishes its current task. On every level of recursion it appends to the variable for updating an array. It picks up the first tags of the XML file but then it starts using that same variable when it goes back to its original task to finish the loop that called the recursion.

So I guess I need to find some way to keep the variable local to that particular time that it was called?

I just read what I just typed, it's so damn abstract, I have trouble comprehending it.

I was considering posting some code, but I'm up to my neck in versions, and I don't even know which version I would post.

Thanks.
C

For In Loop Question / Recursive Function
Hello all,

im trying to place dublicates of a Prototype Movieclip to specific Frames within a for in Loop by dublicating to specific Frames in the Timeline.

could anybody tell me if this is possible

i was googling around for Decades now and cant find any reference material anywhere

For Example in my XML File there are:
<FolderNodes> <SubFolderNodes><LinkNodes>
ActionScript Code:
placeClips = function (timeline)
{
    for (var a = 0; a<TheNode.length; a++)
    {
       
_root.dublicateMovieClip("dynamic", "newClipName", 10, {_global.anchor = this.obj});
       

            placeClips(_remote.timeline[currentFrame +1]);
        }
    }
}
placeClips(this);

to show you exactly what im trying to do :www.mat3d.com/treemenu/index.html

the Function Forward Backward is actually running on the first two subfolders @ the First Branch .But i want it to be simply Administrable with the xml Files
so the whole Tree should be configurable over the xmlfile without any Flash knowledge.So we need this recursive function

could anybody point me to a good tutorial or Hint

Help would be greatly appreciated !

thnx Mat

Recursive Function Yields Undefined
Hello happy people,

I have this function that I want to summarize number given from an array. If the out put total exceeds the variable maxSum I want the function to run again until it gets an result equals or lower than the maxSum.

Now when I test this I "undefined" as out put when the recursion is triggered. Below is my example code to test from. I hope that someone could help me solve this and hopefully explain what I've done wrong ...


PHP Code:



var myTimes:Number = 3;var maxSum:Number = 20var myArray:Array = new Array(6,5,6,9,8,6,6,8,6,9,5,7,8,5,6,8,7,9,7,5,5,8,5,7,5,5,5);function calcSum(times:Number, array:Array) {    var outPut:Number = 0;    var sumarize:Number = 0;    for (var i:Number = 0; i<times; i++) {        sumarize = array[random(array.length)];        outPut += sumarize;    }    //Check so that the outPut isn't greater then the maxSum    if (outPut > maxSum || outPut == undefined) {        calcSum(random(myTimes)+1, array);    } else {        return outPut;    }}my_btn.onRelease = function () {    trace(calcSum(myTimes, myArray));} 




kind regards, Ollu

Recursive Function Not Recursing... I'm Cursing
I have a recursive function thatwalks through an array and, for the time being, just displays a menu tree in a text field set to the variable 'monitor'. However, it will not recurse! It just prints the first row in each level of my tree and poops out. Here's the function:

function traverseMenu(level:Number, needle:Number) {
spacer = "";
count = 0;
while (count<5*level) {
spacer += " ";
++count;
}
_root.monitor += spacer+"Traversing level "+level+" looking for "+needle+"
";
for (row in _root.tree[level]) {
if (row == needle) {
_root.monitor += spacer+_root.tree[level][row]['name']+" : "+row+"
";
next_level = level+1;
for (child in _root.tree[next_level]) {
if (_root.tree[next_level][child]['parent'] == needle) {
_root.traverseMenu(next_level, child);
}
}
break;
}
}
}




Here's what it prints out:


Traversing level 0 looking for 1
Home : 1
Traversing level 1 looking for 2
About Us : 2
Traversing level 2 looking for 12
A Message From The President : 12



Thoughts anyone?

OnRelease = Function() // Recursive Assignment Does Not Work
Hi

there does anybody know why the following can not be turned into a simple loop with for () or while () ?

Help would be appreciated!

Thanks! ;-) Joc.


ActionScript Code:
//
//
this.meal0.meal_M_bg.onRelease = function() {
    _root.mealsAcr.text = mealsAcrArray[0];
};
this.meal1.meal_M_bg.onRelease = function() {
    _root.mealsAcr.text = mealsAcrArray[1];
};
this.meal2.meal_M_bg.onRelease = function() {
    _root.mealsAcr.text = mealsAcrArray[2];
};
this.meal3.meal_M_bg.onRelease = function() {
    _root.mealsAcr.text = mealsAcrArray[3];
};
this.meal4.meal_M_bg.onRelease = function() {
    _root.mealsAcr.text = mealsAcrArray[4];
};
this.meal5.meal_M_bg.onRelease = function() {
    _root.mealsAcr.text = mealsAcrArray[5];
};
//
//

Recursive Function And Bizarre _height Values
disclaimer.. i tend to over look the obvious..but..

i'm trying to return the clip with the largest _height value using a recursive function ..i've modified and used this function in the past for clip counts, removals, etc. and that's worked fine ..again, here i'm trying to get the tallest clip.. but i'm getting some bizarre _height values ..it works when all movieclips have no inner movieclips ..but when i attach a clip inside another clip it blows up on me

..uncomment those last two attachment lines.. you'll see what i mean..

can anyone explain this.. or have a solution to this? THANKS!


ActionScript Code:
attachMovie("mc","mc0",0,{_height:100});
attachMovie("mc","mc1",1,{_height:200});
attachMovie("mc","mc2",2,{_height:400});
attachMovie("mc","mc3",3,{_height:250});
attachMovie("mc","mc4",4,{_height:350});
//mc4.attachMovie("mc","mc5",0,{_height:200}); //traces mc4: 1707.3 (with below line removed)
//mc4.mc5.attachMovie("mc","mc6",0,{_height:150}); //traces mc4: 6246.25

function getTallestClip(mc:MovieClip):MovieClip
{
    var tallest:MovieClip;
   
    for (i in mc)
    {
        if (typeof(mc[i]) == "movieclip")
        {
            //trace(mc[i]._height); //traces each clip's _height
           
            if(tallest == undefined)
            tallest = mc[i];
            else if(mc[i]._height > tallest._height)
            tallest = mc[i];
           
            getTallestClip(mc[i]);
        }
    }
   
    return tallest;
}

var myTallest:MovieClip = getTallestClip(_root);
trace(myTallest._name + ": " + myTallest._height);

Creating A Kind Of Tricky Recursive Function - Help Needed
Hello everybody. I'm in a big big mess, trying to figure out how to do this for the last couple of days. I finaly came to the conclusion that I need a recursive function for what I'm trying to do.

Because it's a little hard to explain what I need.. I'll make an example.
So.. I have the figure below. I mean.. that's what I'm trying to achieve. For that figure I have data stored in the folowing way.

_root.marc is an Array.
All the paths that leave a square ... like From M0 if you choose 1 you'll get M1,
From M0 through 5 you'll get to M3.. and so on.
this is stored like
_root.marc[0].p - the paths. If _root.marc[x].p.length is 0.. that means that Mx is the last one.. and has no paths assigned, like shown in the figure.

My very big problem is that I need to position that MC's.. M3,M4.. all of them, according to the paths above them.

So, to position M2, i need to take a look at M1, and if it has any paths, more than one path, I need to move it further down. But this is not the end of it. If M1 has more paths that lead to other MC-s.. i need to take in considerations their paths too . This drove me mad for the last couple of days, and my time is slowly running out for my diploma

What I've tryed till now was to build a function let's say... getNextY(m) that should return a number. A "ponder"?..
like...to use it in a line like
M2._y = (currIndex + getNextY(1))*dy;// here it should return 5 for instance
M3._y = (currIndex + getNextY(2))*dy;// here getNextY should return 1
Why 5 or one? because it needs to take into account only if the paths are greater than 1.

CRAZY

If any one could help me with this I would be .... I would... I would cry and be greatfull for eternity .. I guess.

Creating A Kind Of Tricky Recursive Function - Help Needed
Hello everybody. I'm in a big big mess, trying to figure out how to do this for the last couple of days. I finaly came to the conclusion that I need a recursive function for what I'm trying to do.

Because it's a little hard to explain what I need.. I'll make an example.
So.. I have the figure below. I mean.. that's what I'm trying to achieve. For that figure I have data stored in the folowing way.

_root.marc is an Array.
All the paths that leave a square ... like From M0 if you choose 1 you'll get M1,
From M0 through 5 you'll get to M3.. and so on.
this is stored like
_root.marc[0].p - the paths. If _root.marc[x].p.length is 0.. that means that Mx is the last one.. and has no paths assigned, like shown in the figure.

My very big problem is that I need to position that MC's.. M3,M4.. all of them, according to the paths above them.

So, to position M2, i need to take a look at M1, and if it has any paths, more than one path, I need to move it further down. But this is not the end of it. If M1 has more paths that lead to other MC-s.. i need to take in considerations their paths too . This drove me mad for the last couple of days, and my time is slowly running out for my diploma

What I've tryed till now was to build a function let's say... getNextY(m) that should return a number. A "ponder"?..
like...to use it in a line like
M2._y = (currIndex + getNextY(1))*dy;// here it should return 5 for instance
M3._y = (currIndex + getNextY(2))*dy;// here getNextY should return 1
Why 5 or one? because it needs to take into account only if the paths are greater than 1.

CRAZY

If any one could help me with this I would be .... I would... I would cry and be greatfull for eternity .. I guess.

Trace Function
Hey, I'm fairly new to flash and for some reason the stupid
trace("message"); function WILL NOT WORK! I can get error messages of course, but for some reason nothing happens when I use trace, and I know I am using it correctly. Any idea why?? Its very hard to learn when I cant use this funtion and tell if my variable are being set or not. I've tried using it everywhere...inside movie clips
onClipEvent(enterFrame){
trace("whatever");
}
in the first frame of my actions layer..
trace("whatever");

in buttons...
on(rollOver){
trace("whatever");
}

wont work!

Trace Function
I'm having a problem getting the trace("message"); function to work. An output window is supposed to pop up and display the message, but nothing happens...I know I am doing it right, its probably the easiest function in Flash, but it doesnt work! And no, the "omit traces checkbox" in the publish setting section is not on! I have no idea what to do, please help! Thank

Trace() Function
Hey, I'm pretty new to Flash, and I can't get the trace function to work. I know I know, its the easiest function in Flash. but it wont work. I have Flash MX on my computer and my computer at work. Neither one will work. If you open a brand new file, open the Actionscript panel, and type trace("hello world"); then hello world should be printed to the output window right? I tried putting a trace inside an onClipEvent of a movie...I know the onClipEvent was being called, but the trace was not working. Someone told me to check the publish settings because the omit trace option might have been checked....nope. Its fine. So someone please tell me how to get it to work. Thanks!

Trace() Function
Hello everyone!
Well I know trace() function is supposed to send messages in the debug windows in order to check errors, etc, .... But recently, I downloaded an online flash game and I found the trace() function in many frames. I was wondering, if there is no debug window, does the trace() function has any useful job?! Moreover, does it allow to send logs to the site?!
Any urgent reply is highly appreciated (zahikaram@hotmail.com)!
Thanks!
Zahi

Problems With "recursive Function Call."
I’ve written a piece of practice code to make a graphic of a jet fly across the screen & leave in it’s vapour trail a name entered in a text field on the previous frame. So a user enters their name in frame 1 presses a submit button & on frame 2 a “Welcome” message appears with the jet spelling out their name.

What I wanted to achieve was the effect of the letters slowly “disappearing” as they would in a real vapour trail. In an “if “ condition I have said if the _alpha of the current field is less than 30 call a recursive function on the rest of the letters, to slowly get them to disappear – it all works great BUT…. Once the current field hits the 30 _alpha mark it stops reducing it’s own _alpha, obviously because control has been handed over to the next field via the recursive function. How can I get round this?

Many thanks

Below is the relevant section of code from the “dim()” recursive function. Full fla also attached.


Code:
function dim(field) {
_root.onEnterFrame = function() {
field._alpha -= 5;
if (field._alpha<=30) {
count++;
dim(_root["f_"+count]);
}
if (count>=input.length) {
_root.onEnterFrame = null;
}
};
}

Trace Function Over-ride
is there a way to override the trace function? for instance it will return 0 instead of tracing out text?

Trace Function Not Working
everytime i use a trace fucntion, i areas I know work, as I have tested via other means, the trace fails to show in the output window!

anyone else ever have this problem?

Trace Function Not Working
I am trying some very simple code and I can't get it to work. To debug, I tried using the trace function and that doesn't even work! I opened a new doc, I added it to an old doc, but nothing seems to work!

Code sample
var myNum:Number;
pic_btn.onRelease = function () {
gotoAndPlay(2);
myNum = 0;
trace(myNum);
}

contact_btn.onRelease = function () {
gotoAndPlay(2);
myNum = 1;
trace(myNum);
}

The gotoAndPlay works but the variable doesn't get set and the trace function does not fire. What am I missing. Please help if you can!

Thanks,
Roachmoe

[F8] [AS2] Trace Function Not Working
Guys, here's the hell thing:

I have two flas, with two different movieClips that extends differents Classes.

The first .fla loads the second: just like Default.fla load catalog.fla
all the functions are working just Ok, but... on the movieclip at catalog.fla, the class dont show ANY trace, eventhough it runs into all the functions.

I have even created a dinamic textfield and in the constructor function of the class I set some text and it did it, just well... what proves my functions are all working, but from any hellish reason I cant see ANY trace, so I just am not able to debug this damn class.

Could someone help me? please.

trying to be a little more expecific:
I have default.fla who has a movieClip called main. Main is a Class who extends Controller class.
And I have catalog.fla who has a movieClip called photos. Photos is a Class who extends Remote class.

so photos runs inside main. all the actions are ok, but It just stop showing me the traces of ONLY the Photos Class!

My Trace Function Not Working
hi i am trying to trace "newcolor" but its not working

_root.clr10.onRelease = function () {

newcolor = "w10"

}

function objDrop2()
{

var _loc3 = this.newgrid1.attachMovie(newcolor, "obj" + String(objCountx), objCountx);
trace(this.newgrid1[newcolor]._name);

}

Trace Function Not Work
Hi ,

I am new in flash,

I make a movie clip in main timeline, its name circle. In circle time line, frame1 I put a variable.Then in main time line (_root) I try to trace the variable.The code is :
trace(circle.myVar)

but it doesnt work, output is : undefined.

However if I trace it using button which I put in main time line, the code is :

on(release){
trace(circle.myVar)
}

it works. So what wrong with it,

Trace Function Won't Work But Why?
Okay, I used to use Flash MX+ and AS1 & AS2 alot and am now ramping up to AS 3.0. This sounds simple and dumb, but I cannot for the life of me get the trace() function to work. If I put this into a new .fla:

function hello(){
trace('Hi');
}

hello();

I get nothing. Blank. Nothing in Output or anywhere. Can anyone tell me why? I know trace() should be simple and I used to use it a ton. Please help!

Thanks in advance!

Why Does Trace Function Not Work?
hi,

ive just started actionscripting instead of tweening so be gentle!

i use mx 2004 but i cant get the trace function to work.., here is the code form a kirupa tutorial...

_global.myvar=5;
trace (_global.myvar);

why does this not work? i thought it shud display 5.

ta, Billy

WTF Function Executes Trace But Nothing Else...
OK here is my issue...I have a main map with a minimap which has a selection box that displays the current view of the main map...you can zoom by way of mouse wheel scroll, +/- buttons, and a wheel which you can click/drag and turn to zoom in and out...thats all fine and dandy, but when you zoom to the max, the selection box in the minimap is slightly shifted out of place...I have a reset function that resets to the original position and scale...this function can be triggered by way of a button...it is also supposed to be triggered when the maximum zoom out (full size) is achieved...now I have set up traces to see what is going on, and infact the function is triggered when the maximum zoom out is acheived because I have a trace at the end of the reset function to display executed...however the other parts of the function( the resetting parts) do not execute unless I click the button...any ideas? you can see what i am talking about at the following link... http://www.expocadvr.com/temp/default.html

just click the minus once and you will see the really minor shift in the selection box of the minimap...now click the reset button, and everything looks fine...but then when you try to zoom out again...the selection box shifts a few pixels down and to the left...any ideas?


ActionScript Code:
//--------------------------------- code for zoom functionality -----------------------function scaleUp(){    var scl = zoom._xscale * 1.1;    zoom._xscale = zoom._yscale = scl;    miniWin._xscale = miniWin._yscale = (1 / (scl * 0.01)) * 100    checkBounds(0,0,0,0);}function scaleDown(){    if(miniWin._xscale >= miniTemp)    {        resetFunc();        trace("wtf is going on");    }    if(mc_scale < (zoom._xscale * 0.9))    {        var scl = zoom._xscale * 0.90;        zoom._xscale = zoom._yscale = scl;        miniWin._xscale = miniWin._yscale = (1 / (scl * 0.01)) * 100    }    else    {        resetFunc();    }    checkBounds(0,0,0,0);    trace(miniTemp + " " + miniWin._xscale);}//--------------------------------- end code for zoom functionality -----------------------//--------------------------------- code for reset zoom & position functionality -----------------------function resetFunc(){    _global.zoom._xscale = _global.zoom._yscale = mcScaleTemp;    miniWin._xscale = miniWin._yscale = (1 / (mcScaleTemp * 0.01)) * 100;    _global.container._x = mc_X;    _global.container._y = mc_Y;    miniWin._x = container_m._x;    miniWin._y = container_m._y;    trace("executed");//this trace works every time(zooming out completely and clicking the reset button...but the other lines above only get executed when the reset button is clicked...}//--------------------------------- end code for reset zoom & position functionality -----------------------  

Trace (function Return Value);
I'm having trouble refering to the return value of this function. I have done this before but not with a mouseEvent function. Can anyone tell me how to trace blueClick so that I can get the return Value

var theHolder:MovieClip = new the_Holder();
var theContent:MovieClip = new the_Content();


blueBtn.addEventListener (MouseEvent.CLICK, blueClick);

function blueClick (event:MouseEvent):Object {
with(theHolder){
addChild(theContent)
}
return theHolder;
}

trace(blueClick());

Why Does Trace Function Not Work?
hi,

ive just started actionscripting instead of tweening so be gentle!

i use mx 2004 but i cant get the trace function to work.., here is the code form a kirupa tutorial...

_global.myvar=5;
trace (_global.myvar);

why does this not work? i thought it shud display 5.

ta, Billy

WTF Function Executes Trace But Nothing Else...
OK here is my issue...I have a main map with a minimap which has a selection box that displays the current view of the main map...you can zoom by way of mouse wheel scroll, +/- buttons, and a wheel which you can click/drag and turn to zoom in and out...thats all fine and dandy, but when you zoom to the max, the selection box in the minimap is slightly shifted out of place...I have a reset function that resets to the original position and scale...this function can be triggered by way of a button...it is also supposed to be triggered when the maximum zoom out (full size) is achieved...now I have set up traces to see what is going on, and infact the function is triggered when the maximum zoom out is acheived because I have a trace at the end of the reset function to display executed...however the other parts of the function( the resetting parts) do not execute unless I click the button...any ideas? you can see what i am talking about at the following link... http://www.expocadvr.com/temp/default.html

just click the minus once and you will see the really minor shift in the selection box of the minimap...now click the reset button, and everything looks fine...but then when you try to zoom out again...the selection box shifts a few pixels down and to the left...any ideas?

[AS]
//--------------------------------- code for zoom functionality -----------------------
function scaleUp()
{
var scl = zoom._xscale * 1.1;
zoom._xscale = zoom._yscale = scl;
miniWin._xscale = miniWin._yscale = (1 / (scl * 0.01)) * 100
checkBounds(0,0,0,0);
}
function scaleDown()
{
if(miniWin._xscale >= miniTemp)
{
resetFunc();
trace("wtf is going on");
}
if(mc_scale < (zoom._xscale * 0.9))
{
var scl = zoom._xscale * 0.90;
zoom._xscale = zoom._yscale = scl;
miniWin._xscale = miniWin._yscale = (1 / (scl * 0.01)) * 100
}
else
{
resetFunc();
}
checkBounds(0,0,0,0);
trace(miniTemp + " " + miniWin._xscale);
}
//--------------------------------- end code for zoom functionality -----------------------

//--------------------------------- code for reset zoom & position functionality -----------------------
function resetFunc()
{
_global.zoom._xscale = _global.zoom._yscale = mcScaleTemp;
miniWin._xscale = miniWin._yscale = (1 / (mcScaleTemp * 0.01)) * 100;
_global.container._x = mc_X;
_global.container._y = mc_Y;
miniWin._x = container_m._x;
miniWin._y = container_m._y;
trace("executed");//this trace works every time(zooming out completely and clicking the reset button...but the other lines above only get executed when the reset button is clicked...
}
//--------------------------------- end code for reset zoom & position functionality -----------------------
[/AS]

Flash MX - Replace Trace Function
Hi all,

I wish to replace the existing trace() function within FlashMX with a customised function that outputs these into a text box.

I want to retain the original trace functions in the code so I can turn it on and off.

I've tried movieclip.prototype.oldTrace=movieclip.prototype.t race etc to no avail.

Thanks.

Flash MX - Redefine Trace Function
Hi all,

I wish to replace the existing trace() function within FlashMX with a customised function that outputs these into a text box.

I want to retain the original trace functions in the code so I can turn it on and off.

I've tried movieclip.prototype.oldTrace=movieclip.prototype.t race etc to no avail.

Thanks.

I Need A Function To Recursively Trace() Variables
I am trying to better understand what properties event objects really have because the documentation isn't entirely consistent (The ErrorEvent constructor refers to an 'id' parameter which is not mentioned in the description of the ErrorEvent.ERROR Event). I was hoping to get my hands on a good function to trace ALL of the properties of a given Event. Sadly, this one I wrote doesn't seem to work for some reason (output is empty).









Attach Code

package {
public class JTA {
static public function traceRecursive(obj:*) {
for(var key:String in obj) {
trace(key + ":" + obj.key);
}
}
}
}

Fire A Function Whenever Trace Is Called?
Is it possible to

firstly:
fire a function whenever trace is called?

secondly:
pass the trace arguements to that function?



I am building a debugger window for online sites

Cheers

Trace Function Works, But No Rollover
stop();
Titletext.onRollOver = function() {
this.gotoAndPlay(2);
}
Titletext.onRollOver = function() {
trace("working");
this.useHandCursor = false;
}

thats my code on frame one in an action layer. above the action layer is a "title" layer that contains one keyframe with the image in it; and above that layer is the third, and final layer that has 26 keyframes. the instance name is Titletext...

when i trace over the image, everything works fine.

i was looking for an attach option so that i could attach the fla but it seems theres not one. :


! hello everyone. i'm new here and im trying to construct my own flash site. :) learned html in 7th grade and pshop in hs. soph. in college now

Problems With "Recursive Function"
I’ve written a piece of practice code to make a graphic of a jet fly across the screen & leave in it’s vapour trail a name entered in a text field on the previous frame. So a user enters their name in frame 1 presses a submit button & on frame 2 a “Welcome” message appears with the jet spelling out their name.



What I wanted to achieve was the effect of the letters slowly “disappearing” as they would in a real vapour trail. In an “if “ condition I have said if the _alpha of the current field is less than 30 call a recursive function on the rest of the letters, to slowly get them to disappear – it all works great BUT…. Once the current field hits the 30 _alpha mark it stops reducing it’s own _alpha, obviously because control has been handed over to the next field via the recursive function. How can I get round this?



Many thanks



Below is the relevant section of code from the “dim()” recursive function. Full fla also attached.






Code:


function dim(field) { _root.onEnterFrame = function() { field._alpha -= 4;if (field._alpha<=20) { ount++; dim(_root["f_"+count]);}if (count>=input.length) { _root.onEnterFrame = null; }};}

Variables Trace Identically, But One Kills Function
Hi folks,

I've hit a wall here. I have this FLV player that I wrote that works fine outside of this particular problem: I have a function on the _root as follows that plays a video by passing it's URL as a parameter to the method of my FLV player:


Code:
videoName = "videos/CHF-30sec.flv";
playVideo = function(vidPath)
{
trace("vidPath is "+vidPath);
trace("videoName is "+videoName);
vidPlaya_cust.playVid(vidPath);
}


The strange thing is this: if I send the URL as a string into the function using the vidPath parameter, the video does not play--absolutely nothing happens. But if I pass the videoName variable in the playVid function instead of vidPath, the video DOES play. Both variables trace as exactly the same string in the output window, so I don't see how the behavior of playVid() could be different for either case. Can anyone help me out??

How To Access A Function From Loaded SWF / Trace Root
I have a function as part of an imported SWF, but I cannot seem access it through the timeline of the parent movie. My assumption is that I am not using the correct path, but I cannot locate the correct path.

Does anyone know how to trace from the root of the parent timeline to a MovieClip inside of an imported SWF?

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