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








Return Value From Function


Hi,
this should be easy:
I have a little text function that works fine when I have it on frame one of a root MC that loads other MCs at runtime.

ActionScript Code:
function xvStrng(sText:String) :String {
    var revText = "";
    // code modifying sText
    return revText;
}
I also have classes included in the root MC. The classes' functions work fine from all MCs, but non of them has to return anything.
When I put the "xvStrng" function into a class and call:

ActionScript Code:
someVariable = className.xvStrng("someString");
all I receive in "undefined".

Any ideas?

Thanks
David




ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 05-29-2006, 05:34 PM


View Complete Forum Thread with Replies

Sponsored Links:

AS2: What Datatype Should A Function Return, If It May Not Return *anything*?
The title of this post may not make much sense, let me explain...

I have a function:

findSurface(origin:Point, vector:Point, attempts:Number):Point {...}

The function has an obscure use, but the idea is thus: given those three arguments, returns a point IF the 'line' (created by the origin and vector arguments) intersects the object the function is called on. [but that is another story...]

More importantly, if there is no point of intersection at all, what should the function return? Void? Null? Undefined? Object? Or can I use one of those return types instead of Point incase the function does not encounter an intersection?

I'd be glad to try explaining better if anyone might know, thanks.

View Replies !    View Related
Return Function Name (Function => String)
I keep coming across problems where it would be really convenient to get the name of a function in string format - like arguments.callee only a string instead of [Function, Function].

I haven't thought of a way to do this but in my head the keywords 'prototype' and 'override function' keep coming up - albeit that seems like a horrible horrible idea, but Function does extend Object so...thoughts?

View Replies !    View Related
Return From Function Called Within Function
How do I return the output from getTrialsHandler to getTrials when calling getTrials?

// THE CALL
trace( getTrials(1,16) );


// THE FUNCTIONS
function getTrials(day, userID){
var pc:PendingCall = service.getTrials(day, userID);
pc.responder = new RelayResponder(this, "getTrialsHandler", null);
}

function getTrialsHandler(re:ResultEvent, day){
if(!re.result){
trace("ERR: load trials for day"+day);
} else {
trace("SUC: load trials for day"+day);
if(re.result[1] > _root.currentDay){
goto = "closed";
} else if(re.result[0] < 5){
goto = "open";
} else if(re.result[0] == 5) {
goto = "full";
}
out = (re.result[0]+"::"+re.result[1]);
}
return out;
}

View Replies !    View Related
Return Function
Can somebody tell me how can I use return function for my film:
I have a large movie with 20 scenes and in every scene I have a webservice from where can user going to sitemap. But if user choos nothing, can he click return button, and appear again in the same scene and in the same position(I mean keyframe) from where he went.
If someone know return function, please tell me....

View Replies !    View Related
Function =>return Value ?
hey,

I wonder if anyone has any ideas how to do this :
I have a function written

Code:
javascript.openConfirm = function(message_str){
responsSet_bol ="false";
getURL("javascript:var respons = confirm('" + message_str + "');void(0);javascript:window.document.popup.SetVariable('respons_str',respons);javascript:window.document.popup.SetVariable('responsSet_bol','true');");

return respons_str;
}

what i want to accomplish is a confirm window(ok, cancel) and I want the answer to be returned
I call this like so:

Code:
respons = javascript.openConfirm("wilt ge dit?");


the problem is that the string is returned, before an answer is set by the confirm window.

does anyone have any ideas how to do this?

View Replies !    View Related
How To Return In This Function?
Hi guys, hope you can help me on this one.
I have a class to load an XML file. I’m trying this:



Code:
package {
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.*;
public class retornaXML{
private var _xml:XML;
public function retornaXML() {
cargarXML();
}

private function cargarXML():void {
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, xmlLoaded);
loader.load(new URLRequest("LocalData.xml"));
}
private function xmlLoaded(e:Event):void {
_xml = new XML(e.target.data);
trace(_xml);
//THE TRACE HERE WORKS PERFECT AND RETURNS THE XML
}
public function get elXML():XML {
return _xml;
//THIS RETURNS null
}

}
}
I want something like this:

var mivariable:retornaXML = new retornaXML();
trace(mivariable.elXML);

but this trace returns null, since the xml file (I think) is not loaded yet. What should I do?

Thanks in advance.

View Replies !    View Related
HELP-Why Won't This Function Return A Value
I want to get this XML data OUT of the function, but it just won't work. What I am doing wrong??? Tracing "xmlList" gives me the output i want IN the function, but if I can't get it OUT. If i set the function to "String", I still can't get the function to return a value or anyway to get this data OUT of the function. Please help.

var xml:XML;
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader;
xmlLoader.load(new URLRequest("data/imagesT.xml"));



xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

function xmlLoaded(event:Event):String
{



xml = XML(event.target.data);
xmlList = xml.children()[0].child(2);

}

View Replies !    View Related
How To Return A Value From A Function, Maybe
Hello, first post :)

Here is my problem: In the attached .fla, I have a wheel of fortune style game which stops at a random point.

I've been able to test where the wheel stops using hitTest, and would like to output the result to the trace (for now).

My if statement which does the hitTest(s) is nested inside the function which slows and stops the wheel spinning (slowdown).

The problem is that function uses onEnterFrame, so my trace messages go into an endless loop.

So my question is how to test that the wheel has stopped spinning from outside the function, where to put the hitTests? My guess is it could involve getting the function to return a value, but I'm not sure.

Thanks in advance.

View Replies !    View Related
AS3 - Return Value From A Function.
Hey i am having a problem getting a value out of a function. It has been driving me crazy tried many ways of doing this... found a way to accomplish it in the .FLA file and it worked fine. But when i am working in .AS it just doesnt seem to work. Please help!


PHP Code:



public function parseUsers(usrInput:XML)
   {
        var userType:String = usrInput.Users.userType.toString();
        trace("Username: " + usrInput.Users.userName + " User type: " +     usrInput.Users.userType);
        return userType;
   } 




The xml loads find parses fine everyting works inside the function... now how do i get those values out??? and how would i use them in a .swf ? Thanks in advance!

View Replies !    View Related
Function And Return
Hello,
I'm pretty newbie to actionscript 2, so my question might sound easy.
I can't understand the use of 'return' in a function.
If I write

ActionScript Code:
function some(num:Number) {
number = num * num;
}
some(8);
trace(number);

well, it works.

I could also have written

ActionScript Code:
function some(num:Number) {
var number = num * num;
return number;
}
some(8);
trace(number);

It works also, but I'm wondering why not using the first case?
Is 'return' used only where variable names might conflict with the rest of the code?
And, if I use methods within the code, the results of which are global, why should I use the return keyword, which is to resolve the 'locality' of functions?

thank you very much
m.

View Replies !    View Related
Function Return
hey,
I'm trying to make a function in flash to call a confirm dialog box through javascript. I wrote this function to open the confirmdialogbox and then storing the value in a variable respons and then sending this variable to the swf. At the end I return the value.

Code:
javascript.openConfirm = function(message_str){
responsSet_bol ="false";
getURL("javascript:var respons = confirm('" + message_str + "');void(0);javascript:window.document.popup.SetVariable('respons_str',respons);javascript:window.document.popup.SetVariable('responsSet_bol','true');");

return respons_str;
}
Now if I call this function doing this :

Code:
respons = javascript.openConfirm("ben je zeker dat je dit wil?");
the returned value isn't stored in the respons variable.
The reason I think is because the value is returned before you click one of the 2 buttons(ok or cancel).
does anyone have any idea how to avoid this. or an other method so the return value is the same as the button clicked

I really need some help, cause I'm stuck

View Replies !    View Related
[Type Function] Return? Wtf Is This?
I have script that creates an array of numbers, randomly choses one from that list, assigns this number to one of the MC's depth, removes it from the array, then moves on to next MC. The purpose is to randomly generate Depth levels.

v_?? are variables
a_?? array
c_?? Clips (MC's)
i_?? interger counters
f_?? functions

when I "trace" the result for the FishA, it displays [Type Function], OR reports the depth is -16383 (or some ridiculous #)

what have i done wrong? What does [Type Function] mean?

onClipEvent(load){
v_Depth = 0;
a_Depth = new Array();
for(i_Count = 0; i_Count < 30; i_Count ++) {
a_Depth [i_Count] = i_Count;
}
function f_SetupDepth(fv_MC) {
v_Depth = random(a_Depth.length);
trace(v_Depth);
_root[fv_MC].swapDepths(Number(v_Depth));
a_Depth.splice(v_Depth,1);
}
f_SetupDepth(c_Column1);
f_SetupDepth(c_Column2);
f_SetupDepth(c_Column3);
f_SetupDepth(c_Column4);
f_SetupDepth(c_Column5);
f_SetupDepth(c_Column6);
f_SetupDepth(c_FishA);
}

View Replies !    View Related
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...

View Replies !    View Related
Return As Function Parameter
how to return true/false (or anything at all), when the parameter is a function?
code:
function f(g, arg) {
g.call(this, arg);
}
//simple working example
function move(mc) {
mc.onEnterFrame = function() {
this._x += 5;
};
}
f(move, ball);
//not working
function returnV(v) {
return v;
}
trace(f(returnV, true));//outputs undefined
function returnV2() {
return true;
}
trace(f(returnV2));//outputs undefined

View Replies !    View Related
Return Array From Function?
hi,

i have a function that takes an xml file as an arguments, reads the data and puts it into an array.

how do i get that array returned outside of the function?

i've tried " return array; " to no avail.

code:

function loadList(filename) {

audiolist = new XML();
audiolist.ignoreWhite = true;
audiolist.load(filename);
trackArray = new array();

audiolist.onLoad = function(success) {
loaded = true;
totalNodes = audiolist.firstChild.childNodes.length;

for (a=0; a<totalNodes; a++) {
thisCD = audiolist.childNodes[a]
tracklist = thisCD.childNodes.length;

for (i=0; i<tracklist; i++) {
trackArray.push(thisCD.childNodes[i].childNodes[0].nodeValue + ":" + thisCD.childNodes[i].attributes["id"]);
}

}
return trackArray();


}
}


onEnterFrame = function() {
if (!loaded) {
myArray = loadTrackList("tracklist.xml","")
for (i=0;i<myArray.length;i++) {
trace(myArray[i]);
}

}

View Replies !    View Related
What Does The CreateTextField() Function Return?
Hey everyone,

I've tried tracing a number of createTextFeild() functions and keep recieving 'undefined.' I suspect my problem is that the function doesn't actually return anything. Can anyone confirm this?

Thanks,
Greenham.

View Replies !    View Related
Return XMLNode From Function
Why is it that the trace from within the readXML function traces the XMLNode as expected, but the trace from within the onLoad returns undefined?

Shouldn't they trace out the same thing. Why doesn't the readXML function return the XMLNode?



ActionScript Code:
var myXML:XML = new XML();
var itemsNode:XMLNode;
var imageNode:XMLNode;
submitBut.onRelease = function() {
    myXML.load("thisXML.xml");
}

myXML.onLoad = function(success) {
    if (success) {
        trace("From Load: " + readXML(myXML, "Items");
        myText.text = readXML(myXML, "Items");
    } else {
        myText.text = "There was an error loading.";
    }
}

function readXML(startNode:XMLNode, targetNode:String):XMLNode{
    if (startNode.hasChildNodes) {
        for (var i = 0; i < startNode.childNodes.length; i++) {
            if (targetNode == startNode.childNodes[i].nodeName) {
                trace("From read: "+startNode.childNodes[i]);
                return startNode.childNodes[i];
            }
            readXML(startNode.childNodes[i], targetNode);
        }
    }
}



Thanks.

_t

View Replies !    View Related
Return Loaded XML From Function?
Hey everyone

I'm trying to figure out how to do this. I'm making an XMLLoader class, that I want to be able to use like this:


Code:
var myXML:XML = XMLLoader.load("SELECT * FROM table");
trace(myXML); // traces the loaded XML
I just can't figure out how to make the load function inside XMLLoader return the XML object... I can easily register an evenlistener that calls another function when the XML is loaded.. but how do I then make the load function return this XML? I want to do this:


Code:
package
{

public class XMLLoader
{
public function XMLLoader()
{
trace("Constructor called");
}

public function load(sql:String)
{
// Call a php site to recieve XML
// add listener to notice when XML is loaded
// return the loaded XML
}
}

}
The thing is, that I want to keep all event-stuff inside my XMLLoader, so I can use the class like the first example.

One way around it is to make a while loop inside the load function that checks whether a boolean is tru or false. When the XML is loaded, I set that boolean to true and the laod function returns the XML. But it's really taking up all the CPU power, and NOT a nice solution..

In a bunch of other programming languages you have the sleep function, that let's you sleep e.g. a part of a functions code until a variable is set, and then you can return it only when it is set.

How do I do it?

View Replies !    View Related
How To Return The XML Data From Function.
hi,
I am new to ActionScript. i need help from you. how to return and get the xml Data from function. this is my coding.

package {

import flash.events.*;
import flash.net.*;
import fl.data.DataProvider;

public class LoadXml
{
static var xmlData:XML =new XML();

public function LoadXmlFn():XML
{
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("DomainDetail.xml"));
xmlData=xmlLoader.addEventListener(Event.COMPLETE, LoadedXML);
return xmlData;
}

public function LoadedXML(e:Event):XML
{
xmlData = new XML(e.target.data);
return xmlData;
}
}
}

Please help me..
Advance thanks.

View Replies !    View Related
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

View Replies !    View Related
Return More Than One Variable From A Function
Hi everyone:

If, say, I want to return one parameter from a function I can use return word, but what if I want to return more than one?

View Replies !    View Related
Return Function W/ SetInterval
I want to have a function that returns a value...this function will be called by setInterval.

The problem is...the function will return a value. I want to make sure that value goes to the proper variable. How can this be done?

Code:
EX:

function test(someInput){
return (someInput = 'dork');
}

interval_ID = setInterval(test, 10000, someInput);

// let's say i have a variable call "show"
// show should contain the return variable
Now, I tested out to see if I can pass a variable by address or reference to avoid 'return'...but it doesn't work. However, arrays can be used b/c it can be passed by referenced.

For example:
function test (theArray){
theArray[0]='dork';
}

var myArray = new Array();

myArray[0] = 'not a dork';

zeroArray(myArray);

trace (myArray[0]);


If you know how I can accomplish the same concept w/out using arrays, let me know.


thx in advance

View Replies !    View Related
Use Return Key To Trigger Function?
I've got a little form in a movieclip where the student is to do some simple subtraction, then click the Record button to enter the data into a table. Problem is that if someone types in the answer, they naturally want to hit the Return key to enter the data, however, it instead puts a carriage return in their answer and when they try submitting with the Record button, it checks their answer and it is now wrong since the added carriage return does not match the answer they should have. Is there any way to make the Return key trigger the recordIt() function? Here is my code:








Attach Code

recordBtn.addEventListener(MouseEvent.MOUSE_DOWN,recordIt);

function recordIt(num) {
if (diameter.text == "85.80") {
if (difference.text == "1.10") {
MovieClip(this.parent).growth.d1999.text = "85.80";
MovieClip(this.parent).growth.g1999.text = "1.10";
helpText.text = "Good job. Click the button below to do the next year's measurement.";
recordBtn.visible = false;
} else {
helpText.text = "Incorrect result. Try again.";
}
} else {
helpText.text = "Incorrect diameter. Try again.";
}
}

View Replies !    View Related
Return To A Calling Function
I need some help here, please.
I have several buttons calling the bounceOut() function and the bounceOut() function calls the onMotionFinish() function. After that function is finished I want to go back to the original calling function. Can someone help me with this?

First a call is made to bounceOut() when a button is clicked. I have ten buttons.

function bounceOut() {
var smSlide:Tween=new Tween(sideMenu_mc,"x",Regular.easeOut,200,-200,2,true);
smSlide.addEventListener(TweenEvent.MOTION_FINISH, onMotionFinish);

}

function onMotionFinish(event:Event):void {
removeChild(pageTitle);
removeChild(sideMenu_mc);
removeChild(missionContent_mc);
removeChild(missionTitle_mc);

}

View Replies !    View Related
Function, Return Problem
Hi,

I think its a matter of function scope, but I can't get my head around it. I'm simply loading an external file with a variable that I want to pass from the loadVars function. It goes something like this.

count.txt - file
nr - the name of the loaded variable that is in the file
working - a dynamic textfield for the working number
notworking - a dynamic textfield in which I get "undefined"


Code:
loadVarsNum = new LoadVars();
loadVarsNum.onLoad = function(success) {
if (success) {
trace("loaded");
_root.working.text = this.nr;
} else {
trace("not loaded");
}
};
loadVarsNum.load("count.txt");

_root.notworking.text = nr;
Is it because I need to add "..cess):Number'" and in the function "return nr;" ? Or is it because I don't have the "nr" variable when I assign it to the second textfield?

Thank you.

View Replies !    View Related
Return Not Working In A Function
Ok, I have a function that creates a button, it takes the paramaters

bX, bY, bcColor, bbColor, bHeight, bWidth, bHandle;

here is my function


Code:
function createButton(bX:Number, bY:Number, bcColor:Number, bbColor:Number, bHeight:Number, bWidth:Number, bHandle:MovieClip)
{
bHandle = this.createEmptyMovieClip("bHandle", this.getNextHighestDepth());
bHandle.lineStyle(1, bbColor, 100);
bHandle.beginFill(bcColor, 100);
bHandle.moveTo(0, 0);
bHandle.lineTo(bWidth, 0);
bHandle.lineTo(bWidth, bHeight);
bHandle.lineTo(0, bHeight);
bHandle.lineTo(0, 0);
bHandle.endFill();
bHandle._x = bX;
bHandle._y = bY;
return bHandle;
}

Code:
var Handle:MovieClip;
createButton(400, 250, 0xFFFF99, 0xFFFF99, 30, 80, Handle);
//X, Y, Colour, Colour, Height, Width, Handle

Handle._visible = false;
some reason when I try to hide Handle, it doesn't do it, & trace's dont do anything either
it is suppost to create the button & store it in any handle I give it

Thanks in advance

View Replies !    View Related
Delayed Function Return? :/
I know nesting functions inside functions is bad bad, so if I want a function to return a string that is fetched from a php file .. how would that really look?

I mean

ActionScript Code:
private static function getInfo():String {  var urlVariables:URLVariables = new URLVariables();  var urlRequest:URLRequest = new URLRequest("moo.php");   var urlLoader:URLLoader = new URLLoader();  urlLoader.addEventListener(Event.COMPLETE, phpDone);  urlLoader.load(urlRequest);  return .... ? :/}private static function phpDone(pEvent:Event):String {  var xml:XML = new XML(urlLoader.data); return xml.userdata.text()}


Thanks for any insight.

View Replies !    View Related
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();

View Replies !    View Related
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());

View Replies !    View Related
SetInterval To Return A Value From A Function?
Got a little problem here guys... the story goes like this:


ActionScript Code:
function foo() {
 
function setValue() {
value = "ok";
}
 
return value
 
}


The problem here in my case is that the function setValue takes a couple of milliseconds to set the value variable. And when executing foo it returns undefined instead of "ok".

no problem, i'll just have foo return value with a setInterval:

ActionScript Code:
function foo() {
 
function setValue() {
value = "ok";
}
 
function checkIfSet() {
if (value) {
return value
}
}
 
setInterval(checkIfSet, 100);
 
}


...Ofcourse this doesnt work. Flash complains that there is no return value for the function foo.

What i'd need is fooScope.return value, if you catch my drift, but thats wishful coding

Can anyone help me out?
Thanks

View Replies !    View Related
Just Want My Function To Return The Result.. Lol
I have a function like so:

Code:

function login ()
{
var token:AsyncToken = auth.call("uLogin",user_txt.text,password_txt.text);
var tresponder:ItemResponder = new ItemResponder(this.Start,this.onFault);
token.addResponder(tresponder);
}

function Start (event:ResultEvent,token = null)
{
var test = event.result
Alert.show(test);
}
}



I'm coming from a PHP world, so maybe I am in for a world of pain. I just want my login() function to return the result.. without all of this jumping through hoops.

Can I do this?

View Replies !    View Related
Problem Of Return The Value In The Function
i got the coding like this:


Code:


_root.m2.onEnterFrame = function() {
if(this.hitTest(_root.dot._x, _root.dot._y, true)) {
this.gotoAndStop(2);
_root.eff="0.55";
}
}

trace(_root.eff);



but this return undefined in the output panel.
How pass/return the value 0.55 to another variable in function?
i used return but how to call the function seem the function name is no declare.

I slove this problem from morning until now. Anybody know how to slove?

View Replies !    View Related
How To Return A Value From OnEnterFrame Function?
Dear All,

I've already learn about onEnterFrame function...
I need to do so, but I've found that the value cannot pass from the function.
Here are my coding:


Code:


function GetSubCat() {
loadVariables("GetData.dat", this);
this.onEnterFrame = function() {
if (CountCat != undefined) {
SubCat = new Array();
for (j=1; j<=CountCat; j++) {
SubCat[j] = this["SubCat"+j];
}delete this.onEnterFrame;
}
};
return SubCat;
}



On the code above,
I've load some variables from the file: "GetData.dat" which contain CountCat, and SubCat1.... like

Code:


&CountCat = 3&
&SubCat1 = The first Cat&
&SubCat2 = The Second Cat&
&SubCat3 = The Third Cat&



I want to put all the SubCats to an Array.
And return the Array to the script.
for example:

SubCatArray = GetSubCat();

So that the SubCatArray (Array data type) can get the variables from the function.

can anyone help!?

Thanks a lot!

View Replies !    View Related
Function Does Not Return Date Object
Greetings everyone.

If functions are capable of returning objects, and Date is an oject, why does the following code consistently return "myDate" as undefined?


Code:
function cleanDate(date) {
// strip the time from date
var x = date.indexOf(" ");
var y = date.slice(0, x);
// strip apart month, day, and year
z = y.split("/", 3);
// create Date object and return it
myDate = new Date(z[2], z[0], z[1]);
return myDate;
}
hireDate = "10/25/2002 12:00:00 AM";
trace(cleanDate(hireDate));
Thanks in advance y'all.

-a

View Replies !    View Related
Return Value Of A Function Called By SetInterval
Just wondering how I can get the return value of a function called by setInterval.

for example

function hello() {
return "hello";
}

myinterval = setInterval(hello, 1000);

How do I get the return value "hello" from hello() function?

View Replies !    View Related
Return From .onLoad Function Syntax HELP
syntax nightmare ...
I would like to load a XML file and onLoad have it return the text of a specific node to where the LOAD function was called from. I have it all worked out except for figuring out how to RETURN from a .onLoad function. Can I return from a .onLoad? See the code below. The mainXML.onLoad fires correctly, and the XML loads successfully. It does not correctly return the node value back the the function named "fLoadXML" however. It returns this:
"myVar: [type Function]"

That leads me to think that it is returning just this object "mainXML.onLoad" and not the value that is returned to it.

Code:
// define the main xml object
var mainXML:XML = new XML();
// functions that loads the XML data
function fLoadXML(file) {
mainXML.ignoreWhite = true;
mainXML.load(file);
//what to do when it loads
return mainXML.onLoad = function(success) {
if (success) {
trace(mainXML.firstChild.childNodes[0].childNodes[0]);
return mainXML.firstChild.childNodes[0].childNodes[0];
trace("XML Load Success");
} else {
trace("XML Load No Success");
return "Error";
}
};
//return myString;
//load the data
trace("load started");
}
var myVar = fLoadXML("data/xmlData.xml");
trace("myVar: "+myVar);
//


any ideas would be helpfull. I am trying desprately not to have to use any global variables anymore, and this would help me out on that front.

thanks

--mm

View Replies !    View Related
Better Way To Write This Tiny Return Function...?
I have a small function that returns a value for x. I want to find an easier way to determine the 'forward' positions in the array. For instance, if I am at position 4 (out of 4) in the array, and I want to know the next two positions, i.e. I want this function to return 0 and 1. I want to avoid hard coding for each case as you'll see below.

Here it is:

code:
array = new Array(0,1,2,3,4);
currentPOS = 4;

function displayNext(x) {
var x = x;
if (currentPOS + x == (_root.array.length + 1)) {
x = 0;
} else if (currentPOS + x == (_root.array.length + 2)) {
x = 1;
} else {
x = currentPOS + x;
}
return x;
}

displayNext(1);
displayNext(2);


Thanks for any help!

View Replies !    View Related
How To Return Data Within A Function? (a Twist)
im trying to create a generic and reusable function that loads xml data and returns it to a variable..

basically, i want a function that would go fetch data and return that to the variable that's calling it..

here's my current function.


PHP Code:



_global.loadXML = function(link){
    myXML = new XML();
    myXML.ignoreWhite = true;
    
    myXML.onLoad = function(success){
        trace("loaded");

        if(success){
            trace("success");
            xmlData= myXML.toString();
        }else{
            trace("error");
            xmlData="ERROR";

        }
        return xmlData;
        
    }
    
    myXML.load(link);
    
}




then call it like so

PHP Code:



filedata= loadXML("profile.txt");




the variable filedate should have the data returned y the function. however....

The above script should work except... the return funcion:


PHP Code:



return xmlData;




is within another function INSIDE that function... therefore, returning the data only returns it to the PARENT function and not to the variable that's calling it..

can you guys see a solution here?

tea

View Replies !    View Related
Advanced Function Return Problem.
I need some information maybe somebody whom reads this will have had the same problem.....I have a function wich uses a return value from another function.
The second function does some complex mathmatical processes on the data and then the end result is returned at which time the first function uses the returned data to perform its function but (here is the problem) function one doesn't like to use the data returned from function 2 but if i replace function2 (the complex function) with a simple function then everything works fantabulous....so is there some special rule i need to follow to use data returned from a complex function?

complex function code.....doesn't like to use the returned secsxx.....keep in mind though that the returned value (secsxxx) will work in a trace or in a dynamic text box it just doesn't work when the first function tries to use it to perform its function.

Code:



minutesx = min;
_root.view_btn2.onPress = func1x;
function func1x() {
var datex = new Date();
_root.targetMillix = datex.getTime()+((minutesx*60)*1000);
}
function maincountxx() {
var datex = new Date();
var millix = this.targetMillix-datex.getTime();
if (secsx<=9) {
var secsxxx = "0"+secsx;
} else {
var secsxxx = secsx;
}
if (minsx<=9) {
var minsxxx = "0"+minsx;
} else {
var minsxxx = minsx;
}
if (millix>0) {
secsx = Math.floor(millix/1000);
minsx = Math.floor(secsx/60);
secsx = secsx%60;
minsx = minsx%60;
timer_txt.text = minsxxx+":"+secsxxx;
// countdown2 is a dynamic text field
} else {
timer_txt.text = "05:00";
}
//code which reacts to timer reaching 0
if (millix<=0) {
msg2.text = "default";
// code which reacts to timer have time.
} else if (millix>0) {
msg2.text = "alternative";
}

return secsxxx;
}

View Replies !    View Related
[mx04] Return Function Problems
Flash MX 2004. AS 2.0

Hey everyone, trying again with a simpler post. I'm having trouble figuring out how to make a function that is part of an image viewer return the image's width to a variable, which I'm going to use in an equation to center the image on the stage depending on how wide it is. I'm pretty sure the function should work since I got the code out of a flash book, the second part is the part i wrote and need help with. Thanks in advance


Here is the code for the function

public function getImageWidth ():Number {
return container_mc.image_mc._width;
}


And here is where I refernce the function on a loading button


on(rollOver) {
var ImageW:Number = viewer.getImageWidth();
}


Is that the correct way to make a variable = the returned number of the function?

View Replies !    View Related
[MX04] Return Function Problems
Flash MX 2004. AS 2.0

Hey everyone, trying again with a simpler post. I'm having trouble figuring out how to make a function that is part of an image viewer return the image's width to a variable, which I'm going to use in an equation to center the image on the stage depending on how wide it is. I'm pretty sure the function should work since I got the code out of a flash book, the second part is the part i wrote and need help with. Thanks in advance


Here is the code for the function

public function getImageWidth ():Number {
return container_mc.image_mc._width;
}


And here is where I refernce the function on a loading button


on(rollOver) {
var ImageW:Number = viewer.getImageWidth();
}


Is that the correct way to make a variable = the returned number of the function?

View Replies !    View Related
Use Return/Enter Key To Trigger Function?
I've got a little form in a movieclip where the student is to do some simple subtraction, then click the Record button to enter the data into a table. Problem is that if someone types in the answer, they naturally want to hit the Return key to enter the data, however, it instead puts a carriage return in their answer and when they try submitting with the Record button, it checks their answer and it is now wrong since the added carriage return does not match the answer they should have. Is there any way to make the Return key trigger the recordIt() function? Here is my code:

recordBtn.addEventListener(MouseEvent.MOUSE_DOWN,r ecordIt);

function recordIt(num) {
if (diameter.text == "85.80") {
if (difference.text == "1.10") {
MovieClip(this.parent).growth.d1999.text = "85.80";
MovieClip(this.parent).growth.g1999.text = "1.10";
helpText.text = "Good job. Click the button below to do the next year's measurement.";
recordBtn.visible = false;
} else {
helpText.text = "Incorrect result. Try again.";
}
} else {
helpText.text = "Incorrect diameter. Try again.";
}
}

View Replies !    View Related
Event Listener For A Function Return
Hey All,
I am wondering if there is a way to have an EventListener listen for the return of from a class? I am also wondering if I am going about thinking about this the right way. Here is my code:

This snippet creates a splash screen:

PHP Code:



public class Main extends MovieClip {
function splashScreen() {
            var mainSplash:Splash = new Splash //This is my splash screen class
            addChild (mainSplash) //adds the main splash graphic
        }
}




And this is the Splash Class

PHP Code:



package roids {
    
        import flash.display.*;
        import flash.events.*;
        import flash.ui.*
        
    public class Splash extends MovieClip {
        public function Splash() {
            trace ("Splash Initialized")
            
            //Creates a button to start the program
            var mainStartButton:MainButton = new MainButton
            addChild(mainStartButton)
            mainStartButton.x = 275
            mainStartButton.y = 300
            mainStartButton.addEventListener(MouseEvent.CLICK, buttonClicked)
            
        }
        function buttonClicked(event:MouseEvent){
            /* what can I put here to return to the parent that a button has been clicked?*/
            
        }
    }
}




In essence I want the main class to know that the mainSplash is returning that the mouse was clicked. Whats the best way to do this?

View Replies !    View Related
Function Can Return Multiple Type
Hi there.

Ok, I would like to know if someone know how to achieve this.
I have a superclass (singleton) with a static function returning the type of the class.

ActionScript Code:
//  create the singleton
    public static function createWorld(owner:MovieClip):superClass {
    //  init the superClass
        superClass.instance.init(owner)
        return superClass.instance;
    }

I have a child class which is inherit from the super class.

The thing is I want to be able to create my childClass instance like that

ActionScript Code:
var gameworld:classes.childClass = childClass.createWorld(this);

but I have a type mismatch as it return the super class type.

Any idea?
I know that I could get rid of the return type and it will be ok, but I wonder if there is another way to achieve what I want.

Cheers

View Replies !    View Related
A Return Statement Is Required In This Function.
**Error** Scene=Scene 1, layer=Layer 172, frame=1:Line 1: A return statement is required in this function.
function thename(success):TextField {

Total ActionScript Errors: 1 Reported Errors: 1


Code:
function thename(success):TextField {
sideways.text = Displayone;
}

View Replies !    View Related
Return Sprite To Calling Function
HI,
i need to return sprite thats loader content and loaded image height and width to calling function

here my code



class

ActionScript Code:
package com.classes{
    import flash.display.Sprite;
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.events.*;
    public class First extends Sprite {
        public var spr:Sprite;
        public function First() {
            trace("here");
            loadImage();
        }
        private function loadImage():void {
            //spr=new Sprite();
            getBitmap();
            //i want to get spr,height and width of image loaded from getBitmap method
        }
        public function getBitmap():void {
            var loader:Loader=new Loader();
            loader.addEventListener(ProgressEvent.PROGRESS,onProgress);
            loader.addEventListener(Event.INIT,onLoadinit);
            loader.addEventListener(Event.COMPLETE,onLoadcomplete);
            loader.load(new URLRequest("http://www.bittbox.com/wp-content/uploads/2007/03/BB_flowers.jpg"));
            addChild(loader);
        }
        public function onLoadinit(evt:Event):void {
            var _load:Loader=Loader(evt.target);
            trace(_load.height,_load.width);
                                     //return height & width to loadImage method
        }
        public function onProgress(evt:ProgressEvent):void {
            trace((evt.bytesLoaded/evt.bytesTotal)*100);

        }
        public function onLoadcomplete(evt:Event):void {
            var _load2:Loader=evt.target as Loader;
            spr=_load2.content
                                     //return this spr to loadImage method
        }
    }
}



in flas


ActionScript Code:
import com.classes.*;
var ff:First=new First()
addChild(ff);

View Replies !    View Related
How To Return Multiple Variables From A Function?
Newbie question, I'm sorry.

I want to do this:

function myfunction () {
//do stuff here
return lmp, mwA, mwB;
}
and use lmp back in my script where the function was called from.

I've tried it, and I'm not sure I'm doing it right, because it doesn't work.

Help please?

Thanks!

View Replies !    View Related
How Do I Return A Value If The Function Calls A Load()
Hey guys,

I am writing a function that I would like to ping a web service, which sends back JSON data, then return data from the JSON...

i.e. trace(getJSONData(1234));

How can I get it to WAIT until the data is loaded then return what I want?

Right now I have this to get the JSON data in:


Code:
articleFeedRequest.url = "http://url_to_go_to.tv/rpc/get/feed(article_id_exact=" + articleNumber + ")" ; // get the data from the userNumbers feed.
articleFeedLoader.load(userFeedRequest);

articleFeedLoader.addEventListener(Event.COMPLETE, decodeJSON);
How can I package all this into a function itself so I can call the function in a trace or whatever to return the data I am looking for...without waiting for the Event.COMPLETE to trigger a new function. I want to have the same function grab the data AND return it.

Know what I mean?

Thanks a jig!

View Replies !    View Related
Return Value Of Function After EVENT Does Not Work
Hi again,

I made a game and put it into one function. And i want the score given back to my main program: (here only as a trace)


ActionScript Code:
trace(MyGame());

and this is my game (not original... is too long to insert here)


ActionScript Code:
function MyGame ():int {

  ...

  var example:int;

  var myTimer:Timer = new Timer(10, 1000);
  myTimer.addEventListener(TimerEvent.TIMER, fu);
  myTimer.start();

  fu(){
    increases example++ a few times;

    trace("test");
  }

return example;
}

now let me explain: when the "fu" function starts, everthing is fine, but when the Timer ends, the "fu" functions will not be left so that the "MyGame" functions does not return the "example" integer...

When i insert a trace with a text, ("test") the trace is printed, but the function will not be left... so i never get my example-int back out of the MyGame function....

why???

View Replies !    View Related
My Function Will Not Return A Sound Object
I've run many tests on the script below. The function "charToWord" is not casting a sound object properly like it is supposed to. These sounds are all properly defined (code not shown) and the sounds do work, but not when they are passed from the charToWord function. Should I be casting as something else?

I get the following error: TypeError: Error #1009: Cannot access a property or method of a null object reference.




ActionScript Code:
function getIdent(myIdentIs):void
                {
                        soundArray.push(charToWord(myIdentIs.charAt(3)));
            soundArray.push(charToWord(myIdentIs.charAt(4)));
            soundArray.push(charToWord(myIdentIs.charAt(5)));
        }

        function charToWord(char):Sound
        {
            switch (char)
            {
                case 1 :
                    return soundOne;
                    break;
                case 2 :
                    return soundTwo;
                    break;
                case 3 :
                    return soundThree;
                    break;
                case 4 :
                    return soundFour;
                    break;
                case 5 :
                    return soundFive;
                    break;
                case 6 :
                    return soundSix;
                    break;
                case 7 :
                    return soundSeven;
                    break;
                case 8 :
                    return soundEight;
                    break;
                case 9 :
                    return soundNine;
                    break;
                case 0 :
                    return soundZero;
                    break;
            }

View Replies !    View Related
Function Didn't Return RecordSet
I am using amfphp and using AS2 class for remote calls.

I have categories and fetch it through loop and at same time I want t fetch subcategory in another loop inside
the loop based on some id

The function doen't returns the RecordSet.

is there anyway to solve it.

returning doesn't looks working. and I'm just using _global variable get any mysql_query.

Please any one help me.

View Replies !    View Related
Copyright © 2005-08 www.BigResource.com, All rights reserved