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




My Function Won't Read Values



I have a one frame movie with the following function in it.

function setTextboxes (AppName, DragBoxNum, Solution, EPS, Correlation, Report, Device, User, URL) {
if (AppName == CurrentApp1) {
_root.Solution1.text = Solution;
_root.EPS1.text = EPS;
_root.Correlation1.text = Correlation;
_root.Report1.text = Report;
_root.Device1.text = Device;
_root.User1.text = User;
_root.URL1.text = URL;
} else if (AppName == CurrentApp1) {
_root.Solution2.text = Solution;
_root.EPS2.text = EPS;
_root.Correlation2.text = Correlation;
_root.Report2.text = Report;
_root.Device2.text = Device;
_root.User2.text = User;
_root.URL2.text = URL;
} else if (AppName == CurrentApp1) {
_root.Solution3.text = Solution;
_root.EPS3.text = EPS;
_root.Correlation3.text = Correlation;
_root.Report3.text = Report;
_root.Device3.text = Device;
_root.User3.text = User;
_root.URL3.text = URL;
};
};

I'm passing the values from a movie clip like so:

on (press) {
this.startDrag (false);
}
on (release) {
stopDrag();
_global.AppName = "EX 550";
_global.Solution = "Entry level high availability 2U logging appliance";
_global.EPS = "Up to 500 EPS";
_global.Correlation = "Up to 30,000 EPS";
_global.Report = "Up to 30 Days";
_global.Device = "Up to 64 Devices";
_global.User = "Up to 2 Users";
_global.URL = "http:exurltobedeterminedlater";
if (this.hitTest(_root.dragbox1)) {
this._visible=1;
this._x=269.5;
this._y=220;
_root.contents.sec.endY=100;
_global.CurrentApp1 = "EX 550";
_global.DragBoxNum = 1;
setTextBoxes (AppName, DragBoxNum, Solution, EPS, Correlation, Report, Device, User, URL);
} else if (this.hitTest(_root.dragbox2)) {
this._visible=1;
this._x=421.8;
this._y=220;
_root.contents.sec.endY=0;
_global.CurrentApp2 = "EX 550";
_global.DragBoxNum = 2;
setTextBoxes (AppName, DragBoxNum, Solution, EPS, Correlation, Report, Device, User, URL);
} else if (this.hitTest(_root.dragbox3)) {
this._visible=1;
this._x=573.7;
this._y=220;
_root.contents.sec.endY=0;
_global.CurrentApp3 = "EX 550";
_global.DragBoxNum = 3;
setTextBoxes (AppName, DragBoxNum, Solution, EPS, Correlation, Report, Device, User, URL);
} else {
this._x=269.5;
this._y=67;
}
}

So, at the end of the drag event, I'm assigning values to all of these global variables. I've confirmed that they're being assigned via Trace(); within that Movie Clip.

However, when I put the Trace(); below my function on line 1 of the root movie clip, all of my variables come up as undefined. I expected them to come up as undefined initially, but when I finish the drag event, they don't change...is this an issue of scope? Am I not calling the function correctly? Or am I simply an idiot?



ActionScript.org Forums > ActionScript Forums Group > ActionScript 1.0 (and below)
Posted on: 07-22-2004, 06:26 PM


View Complete Forum Thread with Replies

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

Function Populated By Node Values Returning Undefined Values
I have been working on some code which extracts the information from an xml document, styles it with css and then loads the various node values into a text field and arrays. The user click on a link in the text field which calls myFunction using asfunction and that in turn should enter the array values relating to that link into text fields.

Everything in general seems to work OK except the value that is returned to the two text fields on pressing the link in the CCTextField "which in turn calls myFunction" returns undefined for those values of the arrays. I check the agency[2] value in the function that populates the arrays and the value is returned as it shoiuld be so it appears there must be something amiss with myFunction, or at least it would seem so.

Any takers as to what this problem might be?

I have supplied some shortened code below.


PHP Code:



CCTextField.styleSheet = myStyle;
// NOTE: CCTextField styleSheet has been created beforehand
my_xml = new XML();
// NOTE: my_xml has been created beforehand


my_xml.onLoad = function(sucess) {
    if (sucess) {
        processXML(my_xml);
    }
};
// Load up the XML file into Flash
my_xml.load('TEST.xml');
// This is the function that will be called when
// the XML document is loaded succesfully
function processXML(xmlDoc_xml) {
    
    var listText_comm = ""; // List text variable
    var entryNum = 0; // Entry number variable
    var agency = new Array(); // Agency array
    var production = new Array(); // Production array
    
    for (var n = 0; n<xmlDoc_xml.firstChild.firstChild.childNodes.length; n++) {
    
        categoryNodeName = xmlDoc_xml.firstChild.firstChild.childNodes[n].nodeName;
        
        if (categoryNodeName == "client") {
            listText_comm += "<a href='asfunction:_root.myFunction," + entryNum + "'>" + xmlDoc_xml.firstChild.firstChild.childNodes[n];
            trace("client " + xmlDoc_xml.firstChild.firstChild.childNodes[n]);
        } else {
            if (categoryNodeName == "title") {
                listText_comm += " - " + xmlDoc_xml.firstChild.firstChild.childNodes[n] + "</a>";
                trace("title " +xmlDoc_xml.firstChild.firstChild.childNodes[n]);
            } else {
                if (categoryNodeName == "agency") {
                    agency[entryNum] = xmlDoc_xml.firstChild.firstChild.childNodes[n].firstChild.nodeValue;
                    trace("agency " +xmlDoc_xml.firstChild.firstChild.childNodes[n].firstChild.nodeValue);
                } else {
                    if (categoryNodeName == "production") {
                        agency[entryNum] = xmlDoc_xml.firstChild.firstChild.childNodes[n].firstChild.nodeValue;
                        trace("production " +xmlDoc_xml.firstChild.firstChild.childNodes[n].firstChild.nodeValue);
                        entryNum++; // click over the entry number by 1
                    }
                }
            }
        }
    }
    
    trace("AGENCY 2 = " + agency[2]); // this returns agency number 2 OK
    
    _root.CCTextField.text = listText_comm; // CCTextField shows this text OK
}

function myFunction(listItem) {
    clientF = agency[listItem]; // THIS RETURNS undefined ON PRESSING THE LINKS IN CCTextField
productionF = production[listItem]; // THIS ALSO RETURNS undefined ON PRESSING THE LINKS IN CCTextField

    trace(listItem); // this trace = the list item passed by asfunction OK


How To Read Values From Different Database?
Can any expert help me with this...?

I have a flash file that reads variable from a text files(eg. myhobby.txt). That is easy.

&myHobbies=swimming




Now here is the complicated/difficult part

Using the same and only flash file how do I read from different sever/database?

e.g.

there is 3 website sharing the same and only flash files.
-if website 'A' load the flash files it will load 'A' hobbies
-if website 'B' load the flash files it will load 'B' hobbies
-if website 'C' load the flash files it will load 'C' hobbies

that means there is 3 myhobby.txt files altogether in 3 different sever/database.

This is very new to me. Please help.

Thanks!

Can I Use Txt File To Read/write Values From It ?
Hi,

is it possible to use txt file to read values from it and to write new values in it.

I want to create presentation on CD which my users will use to read values about some products and later I will use data of products for calculation of price (depending of product, quantity and discount).

Also can I write cookies from Flash so that I store user info on their computers ?

Thanks,
Oliver
http://www.smarttrain.de

Using Flash To Read Values From Websites
Right first of all I haven't been using Flash for very long so if you're gonna try and explain can you make it as simple as possible...

What I want to do is have a Flash movie diplayed on my website that shows values from other websites, e.g how many posts I have on a particular site etc or on another site etc.

XML Loop To Read Values Of ChildNodes
Ok i need to have a loop run and load the value (attributes) of each ChildNode.


Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<links>
<link name="one" ref="one.cfm"/>
<link name="two" ref="two.cfm"/>
<link name="three" ref="three.cfm"/>
<link name="four" ref="four.cfm"/>
</links>
My current code will gereate the result of:
oneoneoneone

but i need

onetwothreefour


Code:
for (k=0; k<numTabs; k++) {
var allText = rootNode.firstChild.attributes.name;
trace(allText);
}
What can I do?

XML Loop To Read Values Of ChildNodes
Ok i need to have a loop run and load the value (attributes) of each ChildNode.


Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<links>
<link name="one" ref="one.cfm"/>
<link name="two" ref="two.cfm"/>
<link name="three" ref="three.cfm"/>
<link name="four" ref="four.cfm"/>
</links>
My current code will gereate the result of:
oneoneoneone
but i need
onetwothreefour


Code:
for (k=0; k<numTabs; k++) {
var allText = rootNode.firstChild.attributes.name;
trace(allText);
}
What can I do?

How To Read Different Values From Different Domain/website/database?
Can any expert help me with this...?

I have a flash file that reads variable from a text files(eg. myhobby.txt). That is easy.

&myHobbies=swimming




Now here is the complicated/difficult part

Using the same and only flash file how do I read from different sever/database?

e.g.

there is 3 website sharing the same and only flash files.
-if website 'A' load the flash files it will load 'A' hobbies
-if website 'B' load the flash files it will load 'B' hobbies
-if website 'C' load the flash files it will load 'C' hobbies

that means there is 3 myhobby.txt files altogether in 3 different sever/database.

This is very new to me. Please help.

Thanks!

How To Read Different Values From Different Domain/website/database?
Can any expert help me with this...?

I have a flash file that reads variable from a text files(eg. myhobby.txt). That is easy.

&myHobbies=swimming




Now here is the complicated/difficult part

Using the same and only flash file how do I read from different sever/database?

e.g.

there is 3 website sharing the same and only flash files.
-if website 'A' load the flash files it will load 'A' hobbies
-if website 'B' load the flash files it will load 'B' hobbies
-if website 'C' load the flash files it will load 'C' hobbies

that means there is 3 myhobby.txt files altogether in 3 different sever/database.

This is very new to me. Please help.

Thanks!

How To Read Values From A Excel Sheet Or Text File
I want to get the values from an excel sheet and make a graph animation printing one point at a time. I don't know how to get the vaues and assign them to variables. After that I think I can manage. Doesn't need to be a remote access, the excel sheet is in the computer.
Any help welcome, thanks.

Why Does It Not Read Outside Function?
Why does the trace outside the function display "undefined" while the trace inside the function display's the correct value even though I'm using "_global"


ActionScript Code:
de_btn.onRelease = function () {
        _root.ScaleTo(100, 80, 0.5, 0.5, _root.MyBox)
        _global.my_title_txt = 2;
        //trace(_global.my_title_txt);
}
trace(_global.my_title_txt);


Sandman9

Read Function From XML...
Hey guys,
Is it possible to read in functions from xml files?

Here's my rough code, just as an example
Code:

for(i=0;i<nodes.length;i++){
   var mc:MovieClip = _root.loader.attachMovie("buttons","b"+i, this.getNextHighestDepth(), {_y:i*20});
   mc.myText.text = nodes.attributes.info;
}

What I would like to do is have my xml file define a function, a-like so:
Code:

<xml node="1" functions="trace("Something");"/>
when my flash file calls it, a-like so:
Code:

mc.onRelease = function(){
  xml.attributes.functions();
}

I know that's not perfect syntax, but do you see what I'm saying/suggesting? Is this possible?

Function To Set Values
I want to assign a value to a variable with an alternate to be assigned if the value is not valid.

In perl, I would say:

Code:
myVariable = something || something_else;


What is the easiest way to do this in ActionScript?

I tried:

Code:
function setValue(which,val,alt) {
if (val == null || val == undefined)
which = alt
else
which = val
}

var myVariable = "test"
setValue(myVariable,"Value","Alternate")
trace(myVariable)


...but that doesn't work. I tried looking in the Flash manual for how to pass variable pointers, but as usual, the Flash manuals have proven to be no help.

HELP Need A Function To Return 2 Values
ok, i've written a function and im trying to get it to return 2 different values

example of what i need


Code:
thisArray = myFunction(args)
----output----
thisArray[0] = first value
thisArray[1] = second value
is there a way to do this?

or do i return 1 string value which is a concantenated string of 2 values with an identifier in between?


Code:
thisVariable = myFunction(args)
thisArray = split(thisVariable, ":")
----output----
thisArray[0] = first value
thisArray[1] = second value
where the : is the identifier

im trying the second method now, but for some reason it returns 'undefined' all the time...

Can You Trade Function Like Values?
Hello, I was wondering can you do something like the following?


Code:
tempArray[0].onRelease = movArray[0].onRelease;
tempArray[1].onRelease = movArray[1].onRelease;
tempArray[2].onRelease = movArray[2].onRelease;

movArray[2].onRelease = tempArray[0].onRelease
movArray[1].onRelease = tempArray[1].onRelease
movArray[0].onRelease = tempArray[2].onRelease
I have a series of objects that rotates after a function completes. I want to make the objects react as they should for their spot. Any ideas?

Different Return Values For A Function?
Hey,

I have a function which could return different types of possible datatypes,
depending on the input. What should i set to be the return value of the function in the definition?

Isn't this ok:

ActionScript Code:
public function getSubData(inDataType:string):Object {
  var obj_to_return:object;
 if (inDataType == "arr") {
       obj_to_return = global_array; //An array with some sprites in it.
  }
 else if (inDataType == "sprite") {
     obj_to_return = global_array[0]; //A sprite
 }
  return obj_to_return;
}

When using the function in my code:

var sprite_obj:sprite = getSubData("sprite");

i get:
"1118: Implicit coercion of a value with static type Object to a possibly unrelated type..."



Is this possible?
Thanks,
Guy

Passing Values To A Function
Ok I have a gallery.. All the images and the Title of each pic is in a DB, I get the data through xml and create an array object to hold all the image info , eg Title, Filename, Width, Height etc....

I have an onRollOver Function (Thanks Kirupa) that produces hover text

each image in the gallery is added to the mc in a loop,

eg image=myMC.createEmptyMovieClip("img"+i...... etc

and I set the onRollOver Function as shown here....

image.Box.onRollOver = function() {
_root.x = 1;

_root.HT.txt.text = array[counter].strTitle;

this.fader._alpha = 100;

};

How Do I pass the value of array[counter].strTitle into the function...

NB.. image.Box is another MC that creates a little fade effect over the image...
I hope I have explained this properly.

thanks guys

John

Updating Function Values
I have 3 variables on the _root timeline.

var a = 50;
var b = 75;
var c = 100;

then i have a prototype which uses those

MovieClip.prototype.myName = function(a,b,c){
...
}

I then have 3 sliders which change the values or a,b and c.

My question is: How do I get the prototype to update the values of a,b and c as the sliders change the values of the variables?

-Regards,
Halian

Passing Values Into A Function
Last edited by flashspeed : 2003-10-28 at 15:23.
























Hi Guys, I want to pass a value into a function via a button click.
The trouble is, i'm using the function as an onClipEvent(enterFrame) the code I have attempted to use is as follows :


on (release) {
_parent.movePix(180); //this will pass the value of 180 into the function.

_parent.collage.CollPix.onEnterFrame = _parent.movePix;
}

On the Parent M/C this is the function :

function movePix(x) {
this._x += (x-this._x)/20;
if (this._x<=x) {
delete this.onEnterFrame;
mc.onEnterFrame = moveMc;
}
}
When I do a trace(x) inside this function, the value is 180 once, then it is undefined for the rest of the ClipEvent.
Can anyone please help?
Thanx in advance
Speedo

PS :: I'm using MX ::

Dynamic Function Values
When creating a dynamic function, how can I set values within the function? Is there a way to do this? Currently, I'm tucking the values within the object like "button.id=42" but I just need to use them within the function. I can't reference the static name of "valueArray" because the "valueArray" values are always changing.

For example:

Code:


function setButton(valueArray:Array){
//button.id = valueArray["id"]; //want to avoid

button.onRelease = function(){
//trace(this.id); //want to avoid
trace(valueArray["id"]); //want to resolve to the value of 'id'
}
}



Any ideas?

[F8] Creating A Function That Will Read An Imported File
I created this code to read an imported file with nothing but x,y coordinates:

import AreaGraph.VR2Conversions.SampleAsciiVR2files.squar e.vr2;
this.createEmptyMovieClip("square_mc.clip", 1);
square_mc.lineStyle(0, 0x000000, 100);
square_mc.beginFill(0x0, 255, 0, 100);
square_mc.moveTo(line_start_x_coordinate, line_start_y_coordinate);
square_mc.lineTo(line_end_x_coordinate, line_end_y_coordinate);
var i:Number;
for (i = 0; i < 5; i++) {
trace(i);
square_mc.duplicateMovieClip("square_mc2", 1);
square_mc.endFill();
}
this.createEmptyMovieClip("circle_mc", 2);
circle_mc.linestyle(0, 0x000000, 100);
circle_mc.beginFill(0x0, 255, 0, 100);
circle_mc.moveTo(line_start_x_coordinate, line_start_y_coordinate);
circle_mc.lineTo(line_end_x_coordinate, line_end_y_coordinate);
var i:Number;
for (i = 0; i < 37; i++) {
trace(i);
circle_mc.duplicateMovieClip("circle2_mc", 2);
circle_mc.endFill();
}
this.createEmptyMovieClip("triangle_mc", 6);
triangle_mc.linestyle(0, 0x000000, 100);
triangle_mc.beginFill(0x0, 255, 0, 100);
triangle_mc.moveTo(line_start_x_coordinate, line_start_y_coordinate);
triangle_mc.lineTo(line_end_x_coordinate, line_end_y_coordinate);
var i:Number;
for (i = 0; i < 4; i++) {
trace(i);
triangle_mc.duplicateMovieClip("triangle2_mc", 6);
triangle_mc.endFill();
}

This code is suppose to read this file:

(VR2 V00.34)

(NamedView -186352,183508 265712,-66188 Initial)

(View -186352,183508 265712,-66188)

(Background 0)

C 3

P 5 0,0 0,122880 122880,122880 122880,0

0,0

P 37 -12587,58659 -13906,73739 -17822,88362 -24217,102083

-32896,114486 -43596,125195 -55992,133884 -69708,140289

-84328,144217 -99407,145547 -114488,144241 -129114,140336

-142840,133953 -155250,125284 -165967,114592 -174666,102203

-181082,88492 -185022,73875 -186364,58797 -185070,43715

-181177,29086 -174804,15355 -166145,2938 -155462,-7788

-143080,-16496 -129374,-22924 -114760,-26875 -99683,-28229

-84600,-26947 -69968,-23065 -56232,-16704 -43808,-8054

-33074,2620 -24356,14995 -17917,28696 -13955,43306

-12588,58383

P 4 142892,-6950 204332,115930 265772,-6950 142892,-6950

(EndOfDWF)

Again all this file is, is x,y coordinates. The P and the # next to it are the number of points. I am trying to create a function that will break these points up and then loop the amount points their are. Is this possible?

Function Returning Mulitple Values
Can I set it up so that a function returns more than one value?

Function Not Retrieving Property Values
Hi there,

This should be a simple one:

I'm trying to create a function that moves a movie clip within a specified range.

I'm defining the function on the main timeline and then running it using setInterval when a button is pressed:

function makeMovieGoDown (){
if (_root.Movie._y >= 10){
_root.Movie += 3
}
}

I've read about this somewwhere before but can't remember the solution. For some reason the function only will only access _root.Movie._y once, and not with every itteration of the setInterval ....


Can anyone explain to me why ?

cheers

GetTimer() Function, How To Stop And Get Values?
I have variables attached to the getTimer() function that returns mins/seconds/miliseconds etc.. which is all nested within an onEnterframe() function. What I am trying to accomplish is the ability to run another function that will stop the getTimer function, pull the values at that exact time of mins/second/mili and then move to the next frame.

I keep getting an infinite loop returned.

Changing Property Values From Within A Function
I'm wondering how I can change a property of an instance from within a function inside a method. I have some code here... Basically I just need to set _lynn_idle to false when a tween is occuring and _lynn_idle to true when the tween is finished. Unfortunately I can't seem to simply set it to false or true inside these listener functions like I'm able to anywhere else (seems the variable is only local to the function when I need it to access the variable associated with the instance). Any help is much appreciated.







Attach Code

private var _lynn_idle:Boolean;

public function moveToTile(tilecoord:Array):Void {
// move lynn with a tween
var startx:Number = _lynnmc._x;
var starty:Number = _lynnmc._y;
var endx:Number = (30*tilecoord[0])+(30*tilecoord[1]);
var endy:Number = 15*(tilecoord[0]-tilecoord[1]);
// determine how long the tween should take
var movedur:Number = 12;

var moveListener:Object = new Object();
moveListener.onMotionChanged = function():Void {
_lynn_idle = false;
// check depths of props and swap

}
moveListener.onMotionFinished = function():Void {
_lynn_idle = true;
// rebuild floor
_lynn_pos = tilecoord;
_global.room.newFloor();
// doAc() to props
}

var moveLynnx:Tween = new Tween(_lynnmc, "_x", Regular.easeInOut, startx, endx, movedur, false);
var moveLynny:Tween = new Tween(_lynnmc, "_y", Regular.easeInOut, starty, endy, movedur, false);

moveLynnx.addListener(moveListener);
}

Changing Property Values From Within A Function
I'm wondering how I can change a property of an instance from within a function inside a method. I have some code here... Basically I just need to set _lynn_idle to false when a tween is occuring and _lynn_idle to true when the tween is finished. Unfortunately I can't seem to simply set it to false or true inside these listener functions like I'm able to anywhere else (seems the variable is only local to the function when I need it to access the variable associated with the instance). Any help is much appreciated.







Attach Code

private var _lynn_idle:Boolean;

public function moveToTile(tilecoord:Array):Void {
// move lynn with a tween
var startx:Number = _lynnmc._x;
var starty:Number = _lynnmc._y;
var endx:Number = (30*tilecoord[0])+(30*tilecoord[1]);
var endy:Number = 15*(tilecoord[0]-tilecoord[1]);
// determine how long the tween should take
var movedur:Number = 12;

var moveListener:Object = new Object();
moveListener.onMotionChanged = function():Void {
_lynn_idle = false;
// check depths of props and swap

}
moveListener.onMotionFinished = function():Void {
_lynn_idle = true;
// rebuild floor
_lynn_pos = tilecoord;
_global.room.newFloor();
// doAc() to props
}

var moveLynnx:Tween = new Tween(_lynnmc, "_x", Regular.easeInOut, startx, endx, movedur, false);
var moveLynny:Tween = new Tween(_lynnmc, "_y", Regular.easeInOut, starty, endy, movedur, false);

moveLynnx.addListener(moveListener);
}

Insert Values In An Array (within A Function)
Hello,
I can't seem to get values insert in an array. I know it works outsite the function but
when using variables in a function and trying to insert this in an array it does not work.
The values are empty.

But if you uncomment the line someArray.push(a0,a1,a2) and uncommend the for loop it works.

In actionscript 2.0 i could use eval ..but in actionscript 3.0 you have to use this to convert a string to a value.

Does anyone see, what i am doing wrong?


function doSomething() {
var a0:String = "hello";
var a1:String = "why doesn't it";
var a2:String = "work!";

var someArray:Array = new Array();

//someArray.push(a0,a1,a2);

for (var i:uint =0; i<=3; i++) {

someArray.push(this["a"+i]);

}


trace(someArray);

}


doSomething();

Problem Returning Values From A Function.
I need to load data from a database, so I created the following function and placed it in frame 2 on the main timeline.

Code:
getQuestionSet = function (category:String, subject:String, level:Number, count:Number):Array {
var questionSet:Array = new Array();
var writeV:LoadVars = new LoadVars();
var readV:LoadVars = new LoadVars();
// stop browser from returning cached results
writeV.cacheKiller = new Date().getTime();
writeV.category = category;
writeV.subject = subject;
writeV.level = level;
writeV.count = count;
trace(writeV.toString());
writeV.sendAndLoad("getQuestionSet.aspx", readV, "GET");
readV.onLoad = function(success) {
if (success) {
questionSet[0] = readV.pk1;
questionSet[1] = readV.pk2;
questionSet[2] = readV.pk3;
questionSet[3] = readV.pk4;
questionSet[4] = readV.pk5;
questionSet[5] = readV.pk6;
questionSet[6] = readV.pk7;
questionSet[7] = readV.pk8;
questionSet[8] = readV.pk9;
questionSet[9] = readV.pk10;
_root.questions = questionSet;
}
};
return questionSet;
};
I also created a variable in the first frame of the main timeline as so.

Code:
var questions:Array = new Array();
Whenever I try to call the function, it fails to set the value of the questions array. It always appears empty(questions[0]-questions[10] have the value undefined). But, if I check the values from within the function after I have set them, it works, so I know that it is receiving the values. What am I doing wrong?

Code:
questions = getQuestionSet("Art and Music", "Art", 1, 10);
Here is an example of how I have would call the function.
Also, please feel free to give me constructive comments on my actionscripting, I'm still new.

Function Returning Multiple Values?
How can I rewrite this code so that I get all the four values returned in the function each time it is called.


ActionScript Code:
x=0;AverageShare=new Array();for(k=1;k<=10;k++){ AverageShare=update();  trace(AverageShare); trace("x = "+x);}function update(){ x++; for(i=1;i<=4;i++) return x+i;}

Anonymous Function – Return Values
Hello, I will appreciate any help with this problem; let me describe a little bit what I’m trying to do:

I have 2 SWF, one.swf and two.swf
1 LocalConnection to send 1 variable from one.swf to two.swf


one.swf code:

var param:Number = new Number(5);

var sending_lc:LocalConnection = new LocalConnection();
sending_lc.send("_Connection1", "myMethod", param);


two.swf code:

this.createTextField("text1_txt", 1, 20, 20, 100, 20);
texto1_txt.border = true;

var receiving_lc:LocalConnection = new LocalConnection();
receiving_lc.connect("_Connection1");
receiving_lc.myMethod = function (param:Number){
text1_txt.text = param; //just to test values
temp = param;
};

// I need to do this
Switch (“param value”) {
….
}

This code actually works pretty well sending the “ param ‘ from one.swf to two.swf

Problem:

I need to be able to use “param” value out of the function, because a I need to perform a switch with this value, since the function wich receives de “param” value is an anonymous function I don’t know how to do to get the value from outside the function because a don’t have a reference name to the function so, the normal way to return a value is not going to do the job.

I will appreciate any help, thanks

GET Function Returns Most Correct Values, But Not All.
I have a get function defined as such:


Code:
final protected function get data()
:Array
{
return _array;
}
This function is defined in a parent class, and then used in derrived classes. As you can see, this is a GET function that returns an array. I can do things like this without a problem:
trace(data['some_index']); // give correct value

But these gives me incorrect values:
trace(data); // shows blank (i.e.: Nothing)
trace(data.length); // gives length of 0, even thoght it has members

Is there a way to have those operations return correct values?

HELP Function's Returning Values Before Lv.Onload
Hi, everyone. I'm trying to create class that'll call a php file to save data into a mysql database, however i'm stumped with the problem of the function returning the result of the query( 0 if mysql saved the data, >0 if error occured ) BEFORE the onload event is executed.

The data is saved into the database, i just want the savedata function to hold its horses and return the value after the onLoad event is done, is what I'm trying to do reasonably correct ? hope i aint barking up the wrong tree... Or is there a better way to do it ?

I've looked around on the web, found a few posts of users trying to do the same thing, but they ended up asking the same question too.

Thanks in advance !



ActionScript Code:
//IN savedata.as
 
class phpdata.savedata
{
    //Variable declaration and initiation
    private var startMili:Number = 0;
    private var startSec:Number = 0;
    private var endMili:Number = 0;
    private var endSec:Number = 0;
    private var savedata_lv:LoadVars;
    private var returnVal:String;
    private var errno:Number;
    private var execTime:Number = 0;
    private var errnumber:Number = 0;
    private var phpurl:String = "";
   
    function savedata(ssavedata_lv:LoadVars, sphpurl:String):Number{
        phpurl = sphpurl;
        savedata_lv = ssavedata_lv;
    }
   
    function save():Number{
        savedata_lv.onLoad = function() {
            var endTime:Date = new Date();
            endMili = endTime.getMilliseconds();
            endSec = endTime.getSeconds();
            execTime = (endSec*1000+endMili)-(startSec*1000+startMili);
            execTime = execTime/1000;
        }
        if (this.returnVal == "success") {
                return 0;
            } else {
                return this.errno;
            }
        savedata_lv.sendAndLoad(phpurl+"?uniqueID="+getTimer(), savedata_lv, "POST");   
        var startTime:Date = new Date();
        startMili = startTime.getMilliseconds();
        startSec = startTime.getSeconds();
                return this.errno;
    }
}
 
//Code in .fla button
on(release){
    import phpdata.savedata;
    saveCalendar_lv = new LoadVars();
    saveCalendar_lv.quan = abc_txt.text;
    var abc = new phpdata.savedata(saveCalendar_lv, "http://192.168.0.102/testinggrounds/save.php");
   
    save_txt.text = abc.saveit();
}

Cannot Use Array Values Inside A Function
I am trying to use values in an array within a different function than where the array was created.

I created and am attempting to access the array as _global

Is there something special I need to do than I am already doing.

PolishEagle

Returning Values From A Function's LoadVars.onLoad..
Hi all, the subject was a bit cryptic, so i'll explain my question a bit.

im trying to put my loadvars function in a class, savedata, and inside savedata.as is the following codes


Code:
class phpdata.savedata
{
//Variable declaration and initiation
private var startMili:Number = 0;
private var startSec:Number = 0;
private var endMili:Number = 0;
private var endSec:Number = 0;
private var savedata_lv:LoadVars;
private var returnVal:String;
private var errno:Number;
private var execTime:Number = 0;
private var errnumber:Number = 0;
private var phpurl:String = "";
private var loaded:Boolean=false;

public function get errnoa():Number {
return errno;
}

function savedata(ssavedata_lv:LoadVars, sphpurl:String){
phpurl = sphpurl;
savedata_lv = ssavedata_lv;
}

function saveit():Number{
savedata_lv.onLoad = function() {
var endTime:Date = new Date();
endMili = endTime.getMilliseconds();
endSec = endTime.getSeconds();
execTime = (endSec*1000+endMili)-(startSec*1000+startMili);
execTime = execTime/1000;
errno = this.errno;
return errno;
}
savedata_lv.sendAndLoad(phpurl+"?uniqueID="+getTimer(), savedata_lv, "POST");
var startTime:Date = new Date();
startMili = startTime.getMilliseconds();
startSec = startTime.getSeconds();
return errno;
}
}


However, in my .fla, i'm calling the saveit function like this


Code:
import phpdata.savedata;
saveCalendar_lv = new LoadVars();
saveCalendar_lv.quan = abc_txt.text;
//var abc = new phpdata.savedata(saveCalendar_lv, "save.php");
var abc = new phpdata.savedata(saveCalendar_lv, "http://192.168.0.102/testinggrounds/save.php");

save_txt.text = abc.saveit();


and as you might have guessed, saveit returns an undefined variable back !

so my question is,
1) am i on the right track doing this in my current way, or am i barking at the wrong tree altogether ? I'm still quite fresh in terms of flash exposure, so if there's a better way of doing it, i'll appreciate it if you can give me a pointer or two I'm trying to reuse this bit of code by placing it in a separate AS file.

2) how do i get the saveit function to return the correct value once the onload function is executed ? And not before the onload function is done ?

thanks in advance !!

*EDIT the is supposed to be startTime:/*--*/Date

Passing Values To Flash From A Javascript Function..
ok I have this and it works ok:

in my html:

<script language = "JavaScript">
<!--
function PassFlash(){
window.document.movie2.SetVariable("trackNo", "track1");
}
//-->

</script>

and then:

<a href="#" onClick="PassFlash()">Pass The Variable</a>

now that works fine and passes the value to my flash movie but is there any way of making it more useful, passing a parameter to that js function, sorta like:

<script language = "JavaScript">
<!--
function PassFlash(whichTrack){
window.document.movie2.SetVariable("trackNo", whichTrack);
}
//-->

</script>

then calling that function using diff params for "whichTrack"

<a href="#" onClick="PassFlash("track1")">Track1</a>

<a href="#" onClick="PassFlash("track2")">Track2</a>

and so on for track 3, track 4 etc

Now sadly that dont work can it be done? just trying to make a function more useful.

any helo massively appreciated!

Position Values Sent To A Public Function From A String
Hello,

I was wondering if anyone could help me with this. I need to call several instances of the same movie clip, but their position values can't be defined statically in the actionscript window. The postion values are defined by a string that is being received by a public actionscript function.

If anyone could help me with this it would be much appreciated, I know how to load variables from an external file to be used as values, but I don't think this is what I'm being asked to do.

Thanks in advance,
León Dore

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);

Event Handler Function Returns Values - HOW To Get Them?
Hello I probably am not understanding how Events work....well I have function in a class that has this line of code:


ActionScript Code:
this.addEventListener("dataRetrieved", handleHierSelectData);

"dataTrieved" is a custom event that dispatches an event with a variable set to "true".

In another section of my code I have the event dispatch:


ActionScript Code:
public function onGetRecordsResult(result:Array = null):void
{
    // convert the result array into an array
    phpData = new ArrayCollection(result);
   
    // instantiate new custom event, set the appropriate data to send back and
    // dispatch event to parent app or component
    var e:DataRetrievedEvent = new DataRetrievedEvent();
    e.dataRetrieved          = true;
    dispatchEvent(e);
}

From the addevent listener line I call "handleHierSelectData"


ActionScript Code:
public function handleHierSelectData():Canvas
{
    newProgressBar.indeterminate = false;
    newProgressBar.visible       = false;
   
    newHierSelect = new ThreeLevelHierSelect('processData', listLabels, null, phpData);
    //myCanvas.addChild(newHierSelect.generateHierSelect());
   
    return newHierSelect.generateHierSelect();
}

See, handleHierSelectData creates a new component that I need to send to my main application so I am wonder WHERE, AND HOW I can get the returned component from this.addEventListener("dataRetrieved", handleHierSelectData); ??

I am missing something here?

I guess what I want to know is...when you have an event listener and you want the handler function to return something HOW do you catch it and where?

Setting Boolean Values Within Function, So They Don't Confilct
Greetings, all- Here's what I'm trying to do: I have a number of buttons on stage. When you rollover, a movie clip is attached. If you roll out, it disappears; if you click, it stays. Then you can drag it around. I'm using a boolean for the rollout disappearing trick. I've set these up in named functions.
[as]function attachBar(word) {
var showIt=false;
i++;
_root.createEmptyMovieClip("bh", getNextHighestDepth());
bh.attachMovie("infobar", iBar, getNextHighestDepth());
bh[iBar]._x = _xmouse;
bh[iBar]._y = _ymouse;
bh[iBar].tField.text = word;
}
function grabIt() {
showIt=true;
bh[iBar].onPress = function() {
bh[iBar].startDrag();
};
bh[iBar].onRelease = function() {
stopDrag();
};
}
btn1.onRollOver = function() {
attachBar("Blade Runner");
//rollOut function
btn1.onRollOut = function() {
if (!showIt) {
bh.removeMovieClip();
}
};
btn1.onRelease = function() {
grabIt();
};
};[as]

All this works fine for a single button.

When I apply my code to multiple buttons, however, the boolean gets reset with every rollover, and the previously attached mc disappears. I don't want to have to set multiple boolean variables, although I suppose I could name them with arguements.

Anybody have any idea for a solution? Thanks!

Pass Array Values To Function Arguments
hi all,

Maybe someone could help me !

it's possible to do this ?

I have an array with some values and i want to pass this values to a function arguments.

example

var theArray:Array = new Array("test1","teste2","teste3");

function hello(t:Number,a:Array){
// do something
test(a)

}

hello(5,theArray)

function test(arg1,arg2,arg3){

// do something
}

I now that i can do like this:
test(theArray[0],theArray[1],theArray[2])

but there is another way to do that ?

thanks in advance,

AS 2 Function Returning Array Of Vector Of 4 Values
I have a search function that searchs an xml file and i would like every time i find a result to collect 4 values (i,j,m,n) and push them to an array. I need these 4 values to keep them together. Any idea on how to implement this in actionscript 2?

[function]losing Internal Values In SetInterval
Last edited by norseman : 2004-03-12 at 07:07.
























I've seen the other setInterval problem but this seems different cos its to do with an objects properties

I have the following code

ActionScript Code:
factory = function () {
    this.credits = 466320;
    this.crystals = 20;
    this.maxCrystals = 500;
    this.solar = 0;
    this.maxSolar = 5000;
    this.sellPrice = 23;
    this.prodTime = 90;
    this.prodAmount = 276;
    this.productionFlag = false;
    this.startProduction();
};
factory.prototype.startProduction = function() {
    trace("here+maxsolar"+this.maxsolar);
    setInterval(this.jo, 4125);
};
factory.prototype.jo = function() {
    trace("jo is here"+this.maxSolar);
};
pete = new factory();

in the jo function it is unable to find the maxsolar value... nay idea why, using MX NOT 04

cheers


Zen

Object Variables Have Null Values Outside Function
I'm having issues with I think objects. I have declared my variables inside the objects and then I assign variables inside that object function. My problem is I want to be able to access this object outside this function. How can I do this? I found that if inside the object function I call the other function that I want it in then the variables work. However, this is not always good because I don't always want to tell it to run a certain function. Any way around this? Is there a global object or something?

Read HTML OnKeyUp Inputtext To Perform Actionscript Function
Dear all,

I am a newbie in actionscript. I have been trying to read text/numbers/symbols or a combination of them as it is being typed from an text box of an HTML page, to display a small color box using action script. I will give an expample.


Suppose qwert is entered in the textbox, a small red color rectangle must appear.

Supose 1234 is entered , a small blue color rectangle must appear.

Can anyone, try and give me the code for this, i will be greatful to you.

Thanks in advance.

Access Array Values Modified Inside Function
I'm trying to access the 'names' array values from outside the function. The textbox 'txt1' displays the correct values, however the final line won't trace out any value for names[1] (not a problem with array length). I'm sure this is a scope issue, but thought declaring the names array outside of the function would allow for the values created in the function to be accessible outside of the function. Thanks in advance for any help!


Code:
test_xml = new XML();
test_xml.ignoreWhite = true;
test_xml.load("test.xml");
var email = [];
var names = [];

test_xml.onLoad = function(success){
if(success) {
for (var n = 0; n<test_xml.firstChild.childNodes.length; n++) {
var currentNode = test_xml.firstChild.childNodes[n];
names[n] = currentNode.attributes.name;
email[n] = currentNode.childNodes[2].firstChild.nodeValue;
}
for (var i = 0; i<names.length; i++) {
txt1.text += "Name: " + names[i] + "
Email: " + email[i] + "
";
}
}
else {
trace("Problem getting XML");
}
}
trace("Name is: " + names[1]);

XML: Get OnLoad-function To Accept Values / Retrieve The Filename?
Hello all.

I am using the standard
Code:
var xml_group:XML = new XML();
xml_group.ignoreWhite = true;
xml_group.onLoad = loadXMLgroup;
stuff to create an XML handler and a call to the function "loadXMLgroup" to read the data from the XML.

Now, with common, default example code, the way you usually use an XML-handling function is:
Code:
function loadXMLgroup(loaded) {
if (loaded) {
// do stuff with the XML file
}
}
...but is there a way to pass a value to it / retrieve the name of the currently processed file from within the XML?

The reason for this is that I want to use the same function (loadXMLgroup) to load several XML files (several groups) and now I am trying to find an "intelligent" way of handling the data.

Before, I did it with a supervising function (with an interval) that checked if a certain "_root" value was filled and if so (or if it failed / time ran out) it would go to the next file to load... but that way it was slow because it would only load one file at a time and wait until it was done, etc...

Is that already the best way to do it? Is there a way how the XML-handling function (loadXMLgroup) can tell which file it is currently processing and fill a specific named value / array-entry instead of a generic dummy value?

Am I explaining this well enough?

Thanks in advance for your help

Passing Values, AddEventListener, MouseEvent Handler Function Help Request
Hello,

I have pasted the current code below. I wish to have a group of images enlarge and shrink as the mouse passes over them (eventually smoothly, not jerky as they are now, as well as fading from B&W to color on enlargement - but not relevant to this question).

As you can see I have written a separate Grow and Shrink function for each image, but this is very inefficient (I am an old hand at VBScript, but new to Actionscript).

I am seeking a way to pass the instance in question to the function so I can use one grow and one shrink function for any/all of the images that will be used, such as (where "1" is the item passed and "whichItem" represents what I am trying to do here):

galleryLoader1.addEventListener(MouseEvent.MOUSE_OVER, growImage(1));
galleryLoader1.addEventListener(MouseEvent.MOUSE_OUT, shrinkImage(1));

function growImage(event:MouseEvent, whichItem):void {
whichItem.x = whichItem.x - (whichItem.width / 2);
whichItem.y = whichItem.y - (whichItem.height / 2);
whichItem.scaleX = 1;
whichItem.scaleY = 1;
}


...... etc.

When I attempt to pass data at the addEventListener line in the line:

galleryLoader1.addEventListener(MouseEvent.MOUSE_OVER, growImage(1));

I always get errors that tell me I am trying to coerce the mouseevent to a string, and the wrong number of arguments (expecting 2). If I put two arguments in, I get a boatload of errors.

I am new, confused, but thoroughly impressed with Actionscript 3.0. I have only been working with it for about a week now and can do a lot, but this particular thing has me stumped.

THANK YOU for any assistance you can render so I can get this function running. The information is probably in several places, but I do not yet know enough to be able to know where or how to look to get my answer. Your help is of tremendous value and is appreciated.

Best regards,

Dave Xanatos


Code extracts (less the imports, addChilds, Loaders and URLRequests...):

galleryLoader1.addEventListener(MouseEvent.MOUSE_OVER, growImage1);
galleryLoader1.addEventListener(MouseEvent.MOUSE_OUT, shrinkImage1);
galleryLoader2.addEventListener(MouseEvent.MOUSE_OVER, growImage2);
galleryLoader2.addEventListener(MouseEvent.MOUSE_OUT, shrinkImage2);
galleryLoader3.addEventListener(MouseEvent.MOUSE_OVER, growImage3);
galleryLoader3.addEventListener(MouseEvent.MOUSE_OUT, shrinkImage3);
galleryLoader4.addEventListener(MouseEvent.MOUSE_OVER, growImage4);
galleryLoader4.addEventListener(MouseEvent.MOUSE_OUT, shrinkImage4);


function growImage1(event:MouseEvent):void {
galleryLoader1.x = galleryLoader1.x - (galleryLoader1.width / 2);
galleryLoader1.y = galleryLoader1.y - (galleryLoader1.height / 2);
galleryLoader1.scaleX = 1;
galleryLoader1.scaleY = 1;
}

function growImage2(event:MouseEvent):void {
galleryLoader2.x = galleryLoader2.x - (galleryLoader2.width / 2);
galleryLoader2.y = galleryLoader2.y - (galleryLoader2.height / 2);
galleryLoader2.scaleX = 1;
galleryLoader2.scaleY = 1;
}

function growImage3(event:MouseEvent):void {
galleryLoader3.x = galleryLoader3.x - (galleryLoader3.width / 2);
galleryLoader3.y = galleryLoader3.y - (galleryLoader3.height / 2);
galleryLoader3.scaleX = 1;
galleryLoader3.scaleY = 1;
}

function growImage4(event:MouseEvent):void {
galleryLoader4.x = galleryLoader4.x - (galleryLoader4.width / 2);
galleryLoader4.y = galleryLoader4.y - (galleryLoader4.height / 2);
galleryLoader4.scaleX = 1;
galleryLoader4.scaleY = 1;
}

function shrinkImage1(event:MouseEvent):void {
galleryLoader1.x = 130;
galleryLoader1.y = 350;
galleryLoader1.scaleX = .5;
galleryLoader1.scaleY = .5;
}

function shrinkImage2(event:MouseEvent):void {
galleryLoader2.x = 330;
galleryLoader2.y = 350;
galleryLoader2.scaleX = .5;
galleryLoader2.scaleY = .5;
}

function shrinkImage3(event:MouseEvent):void {
galleryLoader3.x = 560;
galleryLoader3.y = 350;
galleryLoader3.scaleX = .5;
galleryLoader3.scaleY = .5;
}

function shrinkImage4(event:MouseEvent):void {
galleryLoader4.x = 730;
galleryLoader4.y = 350;
galleryLoader4.scaleX = .5;
galleryLoader4.scaleY = .5;
}

Bought CS3 But Haven't Read My MX Actionscript, MX2004, Books. Should I Read Them?
I just bought CS3 and I am now debating whether I should read my Flash MX Actionscript bible, Flash 2004 Bible. I should have read them, but It's just hard to fit the time in.

Would I benefit from reading these books when CS3 is Actionscript 3? How much functionality is lost when scripting in Actionsript 2 and 1 as compared to Actionscript 3.

Would it be wiser for me to just learn Actionscript 3 properly and get a book on Actionscript 3 than waste my time on reading old scripting and technology?

Also is MC tween compatible on CS3, actionscript 3.

Generating Random Values For A Variable While Excluding The Already Generated Values
Hey Flashers:

Here's my question this time around. I want to generate random values between 1and 50 for a variable but I want every time I generate the new value to exclude the already generated values from the pool of options. Something like playing the lottery where no two drawn numbers can be the same. Any hints or references to open code will be greatly appreciated.
As always, thanks a lot!

[MX] Weirdness With Values Used By Array Populated Clip Values.
Hi,

I have used invisible buttons on top of some text, as part of a volume control interface.

The text buttons are set out as 0 – 25 – 50- 75 -100 referring to the % that a music tracks volume will change to once a button is pressed – so far so good.

Now to give values to the text buttons in order for them to make the text clip that they are on top of go to & stop & the right frame I have used arrays to give a reference the location of the text clip:

numbs_array = [_root.volHold_mc.vol0, _root.volHold_mc.vol25, _root.volHold_mc.vol50, _root.volHold_mc.vol75, _root.volHold_mc.vol100];

I then reference that in a home made “release” function as “this.monica.gotoAndStop(2);” “monica” being the reference to the address of the clip.

It all works fine except the code seems to make the movie play clips in an order that they have not been designated in the array – Like a button on top of the “25”% value will play the animation for the “75”% clip?

The whole problem is probably much better seen through the movie – the problem section of which i have attached below.

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