Variable In A Function?
Hi,
in a function I need to do som action only once that is only the first time this function is called.
I tried the following : Function Functionname(){ if (_level0.StatesAreIn==null) { set (_level0.StatesAreIn,true); GetStates(); } }
and also: Function Functionname(){ if (StatesAreIn==null) { set (_level0.StatesAreIn,true); GetStates(); } }
In both cases GetStates is performed ALL the times the function is called. What am I doing wrong?
FlashKit > Flash Help > Flash ActionScript
Posted on: 09-18-2003, 06:59 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
[F8] [AS2] Access An Instance Variable From Within A Function Within Another Function
So here is the scenario that has completely stumped me. I have a class, within the class a function and within that function an xml onload handler. So herein lies the problem, I need to store the array of values that I receive from the XML into an instance variable belonging to the class. How can this be achieved?
To illustrate:
Class A {private var values:Array;public function getValues():Void{Xml sendandload code here.xmlReply.onLoad = function(){iterate through xml code and generate array of values.Store this array back into values belonging to class A}}}
using the variable straight up doesn't work.
if I use "this" it refers to the onload function, not the class.
i tried creating another class method called setValue and calling this.setValue(arr) and setValue(arr), but neither of those work.
i even tried combinations of _parent and this, still no go.
The only way I can get it to work is to make reference to _root.class.value, but this is not solid code and is very impracticale, especially if what calls the class doesn't happen to be in the root of the file.
Any ideas would be appreciated.
[Help]Class Function As Function Variable And Using 'this'
Hi, its me again!
I met with a problem now. I was trying to implement the Merry-go-round tutorial in OOP. I created a class, had a function exactly like displayPane function. But here's the problem. The 'this' in displayPane is pointing to the class I created. Not to the object I was about to pass this function to. I thought of maybe static will help. But after some more thought I find out that I need to access some of the class object data i created. This really leave me with a hard time. How can I tell AS to point the this to the object I was about to pass this function to. Is there's any possibility to pass in parameters value while you passing function reference to a variable? (I don't there's this possiblity right)
Thanks in advance. Any help is appreciated.
Pass Variable Function In Function
I'm counting how many elements are are in my XML tree and then adding a button and changing the postioning. I can load the info in perfect, but when I try and pass the color variable to the button function things start to screw up.
PHP Code:
var theXML:XML=new XML();
theXML.onLoad = function()
{
buttonx=10;
nodes=this.firstChild.childNodes;
//trace(nodes.length)
for(i=0; i<nodes.length; i++)
{
newname="button"+i;
_root.mc5.attachMovie("button", newname,20+i);
_root.mc5[newname]._x+=buttonx*i;
new_color=nodes[i].firstChild.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.nodeValue;
newname="button"+j;
mc5[newname].onPress = function (new_color)
{
end_color=int(new_color)
doBlend = 1;
set_interval=setInterval(interval_function,1);
return end_color
}
}
}
theXML.load("xml.php");
I'm totally stumped. Any ideas?
How To Put External Variable's From PHP Into Variable's In A Function
I already echo my variable's the right way. I want to make it possible to adjust collors trougout my database. This is what my PHP file echos:
&homecolor=33ff33&newscolor=000000
this is how my PHP file looks:
PHP Code:
<?php
require("connection.inc.php");
$query = "SELECT name, color FROM outlinecolors";
$result = mysql_query($query);
while(list($name, $color) = mysql_fetch_row($result)) {
print("&$name=$color");
}
?>
This way of using PHP also works for the text I use in my movie, which I let flash put in a dynamic textfield. So I tought that it should be possible to have the variable colors above being used in the next function:
code:
home_btn.onRelease = function() {
outline.fadeColor(homecolor, 100, tweensspeed, test);
};
"homecolor" is the place where the value/echo from php must come (&homecolor=33ff33) so "33ff33" must be in the function in stead of homecolor.
Can anybody help me?
Greets..
Flash 4 Actionscript - Using A Variable In The Function Go To And Stop ("variable")
Sorry to take everyone back to Flash 4, but I have a question about using the Go to and stop command to go to a label in a separate movieclip. Basicly it is like this:
I have a thumbnail movie, each thumbnail has a button over it which sets a variable _level0:ITEMNO per each thumbnail.
I also have a fullsize movie, with several fullsize images that correspond with the thumbnails. Each image is on it's own frame with a label name which is it's item number (ITEMNO).
I want the fullsize movie to Go to and stop ("_level0:ITEMNO")
please help.
Variable + Function ?
The goal > an input text field and a small button next to it - the user types a url into the text field and clicks the button - he/she is taken to that url.
so i set the text field as variable "url" then tell the button to somewhow get the value of "url" and go to it? is this right? something along the lines of this maybe
any info on how i can do this, or directions to a tutorial that deals with this specifically would be very nice
Function And Variable
Hi
May be that's a simple question, but I need to understand it. I have a function. Inside this function I want to create a new variable. If I do it like this -> var iSec2 = this.iGetSec % 10; it does not work. I don't understand why I can not initialize a variable in a function on one line and give it a value.
I can do -> var iGetSec; this.iGetSec = this.iGetSec % 10;
or I can do it without the var, just using
this.iGetSec = this.iGetSec % 10;
So I just want to know why. Cause if i'm outside the function I can initialize a variable and give it a value in the same time but not in the function.
// this.iGetSec % 10; is a value that cahnge each time the function is called.
tanx
Getting A Variable Out Of A Function
How do i get the variable news_compiled out of this function, ie in a different movie clip
PHP Code:
var news_compiled;
var newsXML = new XML();
newsXML.ignoreWhite = true;
newsXML.onLoad = processnews;
newsXML.load("news.xml");
function processnews(success) {
rootHandler = this.childNodes;
nodeHandler = rootHandler[0].childNodes;
nodeHandler.reverse();
if (nodehandler[0].nodename == "news") {
for (var i = 0; i<nodeHandler.length; i++) {
childHandler = nodeHandler[i].childNodes;
news_date = childHandler[0];
headline = childHandler[1];
body = childHandler[2];
news += news_date+"<br><font color='#2D01FE'>"+headline+"</font><br>"+body+"<br><br>";
}
news_compiled = "<b>News</b> <br><br>"+news;
} else {
news_compiled = "Load Error";
}
}
Get A Variable Out Of A Function
so i have a function getting info out of an XML page and there is a variable "i" that is in a for loop that keeps track of the number of lines in the XML page....but i cant call that variable out side of the function....how do i get the value of the variable out of the function
some one help me please....i know its something simple but cant put my finger on it...also i tried global variables with no luck
eddie
[F8] Using A Variable From A Function
I have a varialbe declared in a onPress function i want to be able to use in a different onPress function but i am not able to get this correct....
i have two buttons (pause and play) when a user pauses the sound i want to get a var with the current position of the sound file so i can play the sound file from the appropriate location with my Play button, i have:
//Pause the sound
_root.btnPause.onPress = function() {
var my_sound_position:Number = my_sound.position;
trace(my_sound_position + "in pause");
my_sound.stop();
stop();
}
//Play the sound
_root.btnPlay.onPress = function() {
_root.my_sound.start(_root.btnPause.my_sound_posit ion);
trace(my_sound_position + "in play");
play();
}
the trace for the Pause is correct, but the trace in the Play outputs nothing for the my_sound_position.
ive tried like: _root.btnPause.my_sound_position also and nothing.
how do i use one var in the onPress of one button in a onPress function of a different button???
[F8] Using A Variable From A Function
I have a varialbe declared in a onPress function i want to be able to use in a different onPress function but i am not able to get this correct....
i have two buttons (pause and play) when a user pauses the sound i want to get a var with the current position of the sound file so i can play the sound file from the appropriate location with my Play button, i have:
//Pause the sound
_root.btnPause.onPress = function() {
var my_sound_position:Number = my_sound.position;
trace(my_sound_position + "in pause");
my_sound.stop();
stop();
}
//Play the sound
_root.btnPlay.onPress = function() {
_root.my_sound.start(_root.btnPause.my_sound_posit ion);
trace(my_sound_position + "in play");
play();
}
the trace for the Pause is correct, but the trace in the Play outputs nothing for the my_sound_position.
ive tried like: _root.btnPause.my_sound_position also and nothing.
how do i use one var in the onPress of one button in a onPress function of a different button???
How Can I Take Out A Variable From A Function?
How can I take out a variable from a function?
I have this function and I want to take out the currentlySelected.data variable
Please Help
Code:
var cbListener:Object = new Object();
cbListener.change = function(evt_obj:Object):Void {
var currentlySelected:Object = evt_obj.target.selectedItem;
trace(evt_obj.target);
trace("data: "+currentlySelected.data);
trace("label: "+currentlySelected.label);
};
Use A Variable Name Within A Function?
here's my function....
myInterval = setInterval (TTMO,15);
function TTMO () {
InstanceNameOfMovieClip._x -= (InstanceNameOfMovieClip._x - _xmouse)/10;
InstanceNameOfMovieClip._y -= (InstanceNameOfMovieClip._y - _ymouse)/10-2;
}
instead of using the "InstanceNameOfMovieClip" can i use a variable name? i've tried, but it doesn't work. i also tried using the correct hierarchy too, such as this._parent.VariableName too.
HELP Using A Variable From A Function
Hi,
Probably a simple question but I'm new to this.
I'm retrivning a value from a textfile. The value is a path to a folder containg images. The value retrieved from thePics variable is images/test/
Now my problem, I want the variable test to contain the value from thePics variable. My problem is that the test variable is only accessible inside the function (see comment)
myLoadVars.onLoad = function(success){
if (success){
this.test = myLoadVars.thePics; //
trace(this.test); //correct value here
}else{
trace("no variables loaded");
}
};
//Here is where I want my test variable with the path "images/test/"
this.pathToPics = (test);
The path is the path to the folder, when correct the firstFile.jpg shoud be displayed. If I declare the test variable with:
test = ("images/dragar2/"); everyting is working fine, but not when I retrive it from the textfile inside the function.
Thanks
Is It Possible To Use A Variable In The Name Of A Function?
I'd like to have a number of different functions named something like:
"function1", "function2", "function3", all the way up to function100.
I'd like to be able to call them by adding the the number as a variable. For example:
type = 2;
function+type();
Which would call function2. I'm trying to avoid a huge if/else statement by only calling the functions I need.
Is this even possible? Can a function be called if part of the function name is a variable? Is there another way to join "function" with the variable and then call it? Thanks!
-John
Using A Variable Within A Function
Hi there;
I having a bit of difficulty with assigning a parameter to a 'RollOver; function within a for loop...The function works fine if i 'hardcode' in the parameter, but
if i try to use the var i within the function, it doesnt see it..(code below)
Any ideas on how to pass the variable so the functions 'sees it'
Any help much appreciated!
Code:
for (var i=0; i<=arrayAirports.length - 1; i++) {
item = _root.attachMovie("Signal", "Signal" + i, i);
item._y = arrayCoordsY[i];
item._x = arrayCoordsX[i];
// duplicate airport clips and place them on the stage
item.signalText.destTitle = arrayAirports[i];
item.signalText._visible = false;
item.onRollOver = function() {
WriteLinks(1); //This works
WriteLinks(i);//This doesnt!
}
this.signalText._visible = true;
eval("_root.CurvePoint" + this.thisCurve)._visible = true;
}
}
Take A Variable Out Of A Function OMG
Hi d00ds,
I have a array that gets passed straight into this function
Code:
function handleResult(re : ResultEvent)
{
QuestionSet = re.result;
trace(QuestionSet[0]['Question']);
}
Now I wan't to take the 'QuestionSet' array out of this function and expose it on the first frame (or on the _root. domain) so I can call it from OUTSIDE the function. So for example:
Code:
function handleResult(re : ResultEvent)
{
QuestionSet = re.result;
trace(QuestionSet[0]['Question']); //this works
}
trace(QuestionSet[0]['Question']); //this doesnt work, but i want it to work!!
Now I've tried declaring _global variables, with no luck!:
Code:
function handleResult(re : ResultEvent)
{
QuestionSet = re.result;
_global.Question = QuestionSet
trace(_global.Question[0]['Question']); //this works
}
trace(_global.Question[0]['Question']); //this doesn't work.
Any ideas??
Oh and another note:
I can't use the 'return' line in the function because it still doesnt work because what I use is AMFPHP and that takes al my variables from my PHP and straight inserts them into the above function. This is the whole code:
Code:
stop();
import mx.remoting.*;
import mx.rpc.*;
import mx.remoting.debug.NetDebug;
var gatewayUrl:String = "http://localhost/flashservices/gateway.php"
NetDebug.initialize();
var _service:Service = new Service(gatewayUrl, null, 'HelloWorld', null , null);
var pc:PendingCall = _service.say("Hello world!");
pc.responder = new RelayResponder(this, "handleResult", "handleError");
function handleResult(re : ResultEvent)
{
QuestionSet = re.result;
_global.Question = QuestionSet
trace(_global.Question[0]['Question']);
}
function handleError(fe:FaultEvent)
{
trace('There has been an error');
}
I can't just return the array because first i need to PUT IN the array in order to return it from the function which defeats the purpose!
Use Variable Name In A Function. Please
Just get "undefined" with this:
Code:
hide_current = function() {
trace (_global.Klikk._y);
}
_global.Klikk is "mc_frontpage", which is the name of a movie clip i want to mess with.
I've been googling for an hour now and I can't even figure out what to search for.
[AS2] Add 1 To A Variable Outside A Function From Within
I want to import a new image ever 5 seconds but how can I incriment the counter variable from within the function?
PHP Code:
count=0;
function loadimage(count) {
trace(count);
count++;
loadMovie("images/"+q+"/"+a+"/"+count+".jpg", mc_slideshow);
}
loadMovie("images/"+q+"/"+a+"/"+count+".jpg", mc_slideshow);
intervalID = setInterval(loadimage, 5000, count);
Thanks
Function Name As Variable?
I need a way to call a function from a function. It's not that hard, I know, but the name of the nested function is a variable passed into the first function. Like in setTimer() and other functions in flash, where you have the name of a variable to call. I'm going to have a lot, so doing some cheap if(funcname == blabla){blabla();} won't work. I'm not sure if that makes much sense, but yeah... All my searches return useless things.
Function Into A Variable?
This is something that I'm dealing a lot, if there are links to explain this... great!
i have the following function for example
ActionScript Code:
public function getData() { getHDACAddOn( appFacade.loginSession.sessionToken );}
then i have this if else statement
ActionScript Code:
if (someValue != null) { trace('show me');} else { trace('dont show me');}
where i want someValue to be equal my public function getData();
how do i approach this issue?
HELP Using A Variable From A Function
Hi,
Probably a simple question but I'm new to this.
I'm retrivning a value from a textfile. The value is a path to a folder containg images. The value retrieved from thePics variable is images/test/
Now my problem, I want the variable test to contain the value from thePics variable. My problem is that the test variable is only accessible inside the function (see comment)
myLoadVars.onLoad = function(success){
if (success){
this.test = myLoadVars.thePics; //
trace(this.test); //correct value here
}else{
trace("no variables loaded");
}
};
//Here is where I want my test variable with the path "images/test/"
this.pathToPics = (test);
The path is the path to the folder, when correct the firstFile.jpg shoud be displayed. If I declare the test variable with:
test = ("images/dragar2/"); everyting is working fine, but not when I retrive it from the textfile inside the function.
Thanks
Is It Possible To Use A Variable In The Name Of A Function?
I'd like to have a number of different functions named something like:
"function1", "function2", "function3", all the way up to function100.
I'd like to be able to call them by adding the the number as a variable. For example:
type = 2;
function+type();
Which would call function2. I'm trying to avoid a huge if/else statement by only calling the functions I need.
Is this even possible? Can a function be called if part of the function name is a variable? Is there another way to join "function" with the variable and then call it? Thanks!
-John
Using A Variable Within A Function
Hi there;
I having a bit of difficulty with assigning a parameter to a 'RollOver; function within a for loop...The function works fine if i 'hardcode' in the parameter, but
if i try to use the var i within the function, it doesnt see it..(code below)
Any ideas on how to pass the variable so the functions 'sees it'
Any help much appreciated!
Code:
for (var i=0; i<=arrayAirports.length - 1; i++) {
item = _root.attachMovie("Signal", "Signal" + i, i);
item._y = arrayCoordsY[i];
item._x = arrayCoordsX[i];
// duplicate airport clips and place them on the stage
item.signalText.destTitle = arrayAirports[i];
item.signalText._visible = false;
item.onRollOver = function() {
WriteLinks(1); //This works
WriteLinks(i);//This doesnt!
}
this.signalText._visible = true;
eval("_root.CurvePoint" + this.thisCurve)._visible = true;
}
}
AS Function With Variable
I don't know if this should be in the actionscript section, but since it is pretty basic I decided to post it in here.
I want to set for several movieclips the same parameters. I thought I could do this by using the following script:
ActionScript Code:
function myscript (variable){
variable._x = 12
variable._y = 15
variable._alpha = 50
}
myscript (movieclip1)
myscript (movieclip2)
myscript (movieclip...)
This however sets the x and y coordinate and the alpha of the movieclip 'variable' which of course doesn't exist. Does anybody know another solution besides:
ActionScript Code:
movieclip1._x = 12
movieclip1._y = 15
movieclip1._alpha = 50
movieclip2._x = 12
movieclip2._y = 15
movieclip2._alpha = 50
etc
Targeting A Function Using A Variable
I am trying to target a function from a abutton in a movie using a variable, this targets a mc on the root with one frame with seven functions: one, two, three etc etc, I have seven buttons all instaniated by the same names ne, two, three etc etc, how can I use the insance name to target the function. I tried
inst_name = _name;
_root.functions.inst_name();
I know thiat this doesnt work, is there a way to do this?
SetRGB Function With Variable (MX)
I'm trying to call a function from a button to change the color of a section of my MC (with MX).
Code:
//function is on the root and is meant to affect hilite.color1.lines & hilite.color2.lines
//
function hilite(sect) {
sectColor = paresInt(_root["hilitecolor"+sect]);
hiColor1 = new Color(hilite.color1.lines);
hiColor1.setRGB(sectColor);
hiColor2 = new Color(hilite.color2.lines);
hiColor2.setRGB(sectColor);
trace("hiliteColor = "+_root["hilitecolor"+sect]); // displays - hiliteColor = 0x00FF00 (which is correct)
trace("sect= "+sect); // displays - sect= 1 (which is correct)
trace("sectColor= "+sectColor); // displays - sectColor= (nothing)(this is the problem)
}
As you can see "sectColor" is remaining undefined?????
Variable Inside A Function
Button code:
[code]
on(release){
function textSwitch(mission, mike);
}
Code:
function textSwitch(screen, item){
_root.text = content[screen][item];
}
content.mission.mike = "I am mike";
content.mission.dani = "I am dani";
content.mission.dale = "I am dale";
I know something is wrong with the way I'm implementing the the passed variables into the function. Specifically, content[screen][item] I think is incorrect. Could you tell me how to fix this?
Change Variable From Within A Function
I want to change a variable's value from within a function, but the variable has to be itself a parameter of the function.
for example:
Code:
function myFunction(n) {
n = n-1;
trace(n);
}
x = 5;
_root.myButton.onRelease = function() {
myFunction(x);
};
Call Function From Variable
hi
i have a bit of code that calls a function using a variable - like in this example from Moock:
PHP Code:
var gp = gotoAndPlay;
gp(25);
in my code the variable "returnFunction" is a target path with a function name at the end : "_level0.buttons.button1"
so, in my code it's like this :
PHP Code:
on(release){
trace(returnFunction);
returnFunction("valid");
// _level0.buttons.button1("valid");
gotoAndStop("shut");
}
if i un-comment the line with the path it works fine, and the trace function returns "_level0.buttons.button1" so it should work ...
can anyone tell me where i'm going wrong ?????
thanks
Function Name In A Variable Syntax
HI,
If I have a mc which which contains a button and..
On my maintimeline I declare several functions
function DoStuff() {
what ever in here
}
as I have multiple instances of my mc which I wish to execute different functions when the button closes them I store the name of the function to execute in a variable on load
onClipEvent(load){
FunctionToDo = "DoStuff";
}
what do I put on my button to call the function?
thanks mark
Using A Variable For The LoadMovie Function?
I want to dynamically pull an external .swf into a movie layer based on a users button click. so for example...
user clicks a button....
the movie clip that is playing will go to its closing animation then load this new movie over it.....
i am thinking that the button will set a variable..say (selectedmovie) and the end of each external movie clip will be set up to capture that varialbe in the loadmovie() function.
Can the loadMovie() function accept a variable from a button click in a different movie clip as its movie clip URL???
not sure if this is making any sense..maybe ther is an easier way to do what im trying to do....
thanks
MovieClip Variable Not Available In Function? (MX)
How come this:
code:
for (count=1; count<=111; count++) {
temp = eval("shards.shard"+count);
temp.fallSpeed = randRange(-5, 10);
temp.slideSpeed = randRange(-5, 5);
temp.fallIn = randRange(0, 20);
temp.doesSpin = (randRangeRounded(1, 2));
temp.spinX = randRange(-3, 3);
temp.spinY = randRange(-3, 3);
temp._alpha = 50;
}
for (count=1; count<=111; count++) {
trace (temp.fallSpeed);
}
gives the intented results, however the following comes back undefined?
code:
for (count=1; count<=111; count++) {
temp = eval("shards.shard"+count);
temp.fallSpeed = randRange(-5, 10);
temp.slideSpeed = randRange(-5, 5);
temp.fallIn = randRange(0, 20);
temp.doesSpin = (randRangeRounded(1, 2));
temp.spinX = randRange(-3, 3);
temp.spinY = randRange(-3, 3);
temp._alpha = 50;
}
function crash() {
for (count=1; count<=111; count++) {
trace (temp.fallSpeed);
}
}
crash();
It seems as soon as I put it in a function, the variables loose their value?
Gettin' A Variable Out Of A Function?
MX 2004, this is living on the first frame of the top layer.
I need to pass the _root.sku variable to a dymnamic text box (it has it's var set to _root.sku) That part works fine. The problem is getting the _root.dms1 variable set from the (ext.target.selectedItem.data) value. I get an 'undefined' out of the dms1 and 2 variables. I'm trying to set this value inside a function. The function is pulling the values out of some combobox's (which by the way I finally got working.....)
Any thoughts on how to set this dms1 variable so it can be used elsewhere? Thanks
<snip>
_root.sku = "636" + _root.dms1 + _root.dms2;
listener = new Object()
listener.change = function(evt){
loadMovieNum("http://somewebsite.com/flash/636/" + evt.target.selectedItem.data + ".swf",2);
trace(evt.target.selectedItem.data);
//here's were I'm trying to set the variable
_root.dms1 = (evt.target.selectedItem.data);
}
outerCombo.addEventListener("change", listener)
<snip>
Call Function With Variable In XML
Hi,
Hopefully somebody can help me.
How can I call a function in Flash MX that has a variable, in XML?
To call a function in Flash with XML, you just need to put the name of the function without brackets.
e.g.:
Code:
XML
< tagXML > MyFunction < / tagXML> //this works
< tagXML > MyFunction() < / tagXML> //this doesn't work
Flash
MyVar = Tag.childNodes[0].firstChild.nodeValue;
MyText.text = MyVar
function MyFunction() {
var cText = "Hello World"
return cText
}
My question is now? How do I have to call a function with a variable?
Which text do I have to write in my XML between the tags, to make this work.
I can't add an extra tag for the variable in my XML, because this would change my structure of my XML file, it has to be possible in one tag to call the function with a variable.
e.g.:
Code:
XML
< tagXML > MyFunction("Hello World") < / tagXML > //this doesn't work:(
Flash
MyVar = TagXML.childNodes[0].firstChild.nodeValue;
MyText.text = MyVar
function MyFunction(cText) {
return cText;
};
Variable Declaration Function
if there any way i can make a function like this ...
code: function Dim(Namey:Object){
var Namey:Object = New Object()
Namey.Purple = 9
}
...work to create a variable called Namey with a value of .purple = 9
so
code: Dim(Green);
Trace(Green.Purple);
would return 9
How Can I Access A Variable I Set In A Function.. Outside
in this function:
Code:
myXML.onLoad = function(){
//txtDebug.text += newline + "myXML.getBytesLoaded:" + myXML.getBytesLoaded();
var foo:Wddx = new Wddx();
var myObj:Object = foo.deserialize(myXML);
for(i in myObj) { trace("["+i+"]["+typeof(myObj[i])+"]["+myObj[i]+"]") } //debug
}
i am initializing & setting myObj ... the debugging code shows that myObj is being set properly from my wddx source.
how do i access the myObj variable outside of this function (same frame)..
Code:
for(i in myObj) { trace("["+i+"]["+typeof(myObj[i])+"]["+myObj[i]+"]") } //debug
outside the function, this does not show any output.
Function Variable Problem
Hi Guys,
Hope you can help with a booking form im putting together.
I have a variable inside a function called calDayPref. The variable contains a day (monday or tuesday or....etc etc) this day is picked from a datefield component called calendar_dc.
When the user picks a date, i need to be able to check if the variable calDayPref is Monday to Friday, if so populate a combobox with additems like 4pm 5pm 6pm 7pm etc, if alDayPref is Saturday or Sunday they can book the facility from 9am till 5pm.
The only problem is checking the variable since its inside a function. Will i have to post it to php and then retrieve it again outside of that function. Anyone got any ideas? im stumped.
Here is the code.
Code:
function updateDate(eventObj:Object){
if(eventObj.target.selectedDate != undefined){
var calendarDate = calendar_dc.selectedDate;
var calendarDate2 = calendar2_dc.selectedDate;
}
var nameOfDays:Array = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var nameOfMonths = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var calDayPref = nameOfDays[calendarDate.getDay()];
var calMonthPref = nameOfMonths[calendarDate.getMonth()];
var calDatePref = calendarDate.getDate();
var calYearPref = calendarDate.getFullYear();
var prefDate = +calDayPref + " " +calDatePref + " " +calMonthPref+ " " +calYearPref;
trace("Prefered date is" +prefDate)
var calDayAlt = nameOfDays[calendarDate2.getDay()];
var calMonthAlt = nameOfMonths[calendarDate2.getMonth()];
var calDateAlt = calendarDate2.getDate();
var calYearAlt = calendarDate2.getFullYear();
var altDate = +calDayAlt + " " + calDateAlt + " " +calMonthAlt+ " " +calYearAlt;
trace ("Alternative Date is " +altDate);
}
trace ("Call Day Pref is" +calDayPref);
calendar_dc.addEventListener("change", updateDate);
calendar2_dc.addEventListener("change", updateDate);
updateDate();
Any help greatly appreciated.
Cheers
How To Get Outside Variable Into EventListener Function?
I have this situation:
//-----------------
Code:
import flash.net.FileReference;
class imgUpload{
private var imageFile:FileReference;
public var uploadURL:String;
private var listener:Object=new Object();
function imgUpload(url){
uploadURL=url;
imageFile=new FileReference();
listener.onSelect = function(selectedFile:FileReference, url):Void{
trace(uploadURL);//result is undefined
selectedFile.upload(uploadURL+"?id="+item['biblio_id']);
}
imageFile.addListener(listener);
}
function browse(itm){
imageFile.browse([{description:"Image Files", extension:"*.jpg;*.gif;*.png"}]);
}
};
//------------
i need uploadURL value in listener.onSelect = function. How to get it?
I tryed variuos ways, like this._parent.uploadURL, selectedFile._parent.uploadURL nothing work
[F8] Cannot Use Variable As Function Input?
Code:
myListener = new Object();
fish.addEventListener("click", myListener);
myListener.click = function ()
{
fish(1,_root.fishselect);
};
1= the persons level
2= the variable where "sardine" is stored
when i run the function like that, it doesnt work. but if i replace "_root.fishselect" with "sardine" it works. why???
Function With Changing Variable
hi
it is to late to change this in my project right now, but for future project i'd like to know the following:
i have a button, which should change several movie clips. so i had the button change a variable. the other mcs then check the variable and do whatever procedure is "attached" to that state of the variable. so most of the time if i push a button the following happens: the mcs are doing something with the old state of the variable, then the variable changes and they do something with the new state. my "problem" with that is, that i can't make one funtion out of it, because in the middle of the process the variable is changed to the one specific number that only that button will it give it. so i have to do a function for what happens before the change of the varibale, then change the variable, then have another function for what happens after the change.
is there a solution to that problem?
thanks
Robert
Storing A Function In A Variable... Or Something
hey guys I've got a lil function...
Code:
function getKeyXML(xmlData, searchTerm, storeArray, storeFunction){
and that storeFunction include needs to be a function, but I dont want it to run the function.
Code:
__reg1 = this[storeFunction+"(__reg1)"];
so is there a way do to something like what i dipicted above... where it just sends a string and on run time it runs proper function?
Defining A Variable Within A Function
I am bringing in some values from an XML document and am having mixed success.
I am retrieving an attribute from a node(postit) in the xml doc and trying to assign it to a variable called postTitle in my AS; this happens inside an onLoad function which i believe is an acceptable method when retrieving values from an xml doc. When I trace this variable inside the function it outputs fine however I need the variable to be accessible outside the function as it needs to be displayed with a dynamic text box.
As you can see I have tried defining the variable before the function but when this happens the output is some html tags. The code is annotated.
Thanks in advance. Gareth
Code:
<stickies>
<gcse>
<postit title="Example Title 1" maintext="test text" />
</gcse>
</stickies>
Code:
var postTitle:String;
my_xml.onLoad = function(success){
var gcse = my_xml.firstChild.firstChild;
var postit = gcse.childNodes;
for (var i=0; i<postit.length; i++){
currPostit = postit[i];
var postTitle = currPostit.attributes.maintext;
trace(postTitle);//outputs ok within the function
}
}
trace(postTitle); //does not output at all or outputs html tags (<p align="left"></p>)
[F8] Trying To Create A Function Name With A Variable...
Hi there!
I'm trying to call a function that will have a name that is a combination of a variable and a set text.
For example: I'm trying to call hemmaAnimation(); within a
_global function.
I have a variable in the _root called section.
I set the variable to hemma & call this _global function.
_global.sectionAnimation = function(){
section+"Animation"();
}
But no luck - probably a really simple solution here.
Need help...
All the best, Niklas
Function Local Variable
Hi, im calling a String from an external file, the string is return to a function (has to be for the pluging im using)
The string then needs to be split in to an array which is fine, but the content of the array then needs to be available to the rest of the movie. Its my understanding that the array will be local to the function because it was created in the function so cant be used outside the function.
how can i extract a variable from a function so it is no longet local
any help will be appriciated
[F8] Pass Out A Variable In A Function
Hey,
How can I pass out a variable from a function? So as to set the value of a variable in the same scope that the function was called?
For example (doesn't work...):
function save(vari:Number):Void {
vari = 50;
}
var big:Number;
save(big);
trace(vari);
So as you can see it doesn't do what I want it to do, as it traces undefined (which is expected...). It passes in "big", as vari, which is undefined, then sets it as 50. I don't want that though.
Hopefully you understand what I am asking.
Thanks in advance!
Undefined Variable Outside Of Function HELP
Hi, im pulling in an xml document. Ive pushed all the nodes in to arrays and have successfully performed calculations on some variables. Now, i have the arrays defined as _.global arrays, but when i try and trace them outside the function they are undefined. They trace fine inside the function.
Is ther anyway of accessing these variables outside the function???
this is my file, as you can see at the botttom i am trying to trace the variables but it wont work???
PHP Code:
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("stocks.xml");
_global.indicename = new Array();
_global.currentprice = new Array();
_global.valuechange = new Array();
_global.newLocation = new Array();
function loadXML(loaded) {
if (loaded) {
for (i=0; i<3; i++) {
_global.indicename.push(this.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue);
_global.currentprice.push(this.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue);
_global.valuechange.push(this.firstChild.childNodes[i].childNodes[2].firstChild.nodeValue);
}
for (i=0; i<_global.indicename.length; i++) {
trace("Symbol = "+_global.indicename[i]);
trace("Current Price = "+_global.currentprice[i]);
trace("Value Change = "+_global.valuechange[i]);
_global.mySubstring = _global.valuechange[i].substr(0, 1);
if (_global.mySubstring == "+") {
_global.origprice = parseFloat(_global.currentprice[i])-parseFloat(_global.valuechange[i]);
trace("Original Price = "+origprice);
//Following finds percentage change
_global.percentage = parseFloat(_global.valuechange[i])/parseFloat(_global.origprice)*100;
trace("Percentage Change = "+percentage);
_global.newLocation[i] = _global.percentage*100;
trace("Move To >"+newLocation[i]);
}
if (_global.mySubstring == "-") {
_global.origprice = parseFloat(_global.currentprice[i])-parseFloat(_global.valuechange[i]);
trace("Original Price = "+origprice);
//Following finds percentage change
_global.percentage = parseFloat(_global.valuechange[i])/parseFloat(_global.origprice)*100;
trace("Percentage Change = "+percentage);
_global.newLocation[i] = _global.percentage*100;
trace("Move To >"+newLocation[i]);
}
if (_global.mySubstring == "0") {
_global.origprice = parseFloat(_global.currentprice[i])-parseFloat(_global.valuechange[i]);
trace("Original Price = "+origprice);
//Following finds percentage change
_global.percentage = parseFloat(_global.valuechange[i])/parseFloat(_global.origprice)*100;
trace("Percentage Change = "+percentage);
_global.newLocation[i] = _global.percentage*100;
trace("Move To >"+newLocation[i]);
}
}
}
}
trace(indicename[0]);
trace(currentprice[0]);
trace(newLocation[0]);
this is my xml file,
PHP Code:
<?xml version="1.0" encoding="utf-8" ?>
- <indices>
- <indice>
<BVSP>BVSP</BVSP>
<indiceprice>60532.40</indiceprice>
<valuechange>+80.30</valuechange>
</indice>
- <indice>
<MXX>MXX</MXX>
<indiceprice>30647.39</indiceprice>
<valuechange>+557.49</valuechange>
</indice>
- <indice>
<MERV>MERV</MERV>
<indiceprice>2085.20</indiceprice>
<valuechange>-4.51</valuechange>
</indice>
</indices>
Can You Pass Variable From Within Function?
2 basic questions:
1. Can you pass a 'var' from within one function to another?
2. How do you do it???
Want to pass 'ObjectID' which is made up from a result value into the 'my3d' function. Doesn't register it at the moment?
Code:
public function cbPages(result:Object):void {
var objectID:String = result.title;
trace(objectID);
}
override protected function my3d():void {
cow=new Collada(objectID);
default_scene.addChild(cow);
}
Many thanks for your help in advance.
Getting A Variable Back From A Function...
I've designed a picture gallery that loads external jpgs into a loader component. It all works as long as I have the code on every single thumbnail but when I try to create a function my variable keeps coming back as undefined. Here's what I'm using on the main timeline:
Code:
function thumbFunction (fShot:String):String {
//this bit works just fine
this.colour_btn.glow.gotoAndStop ("down");
this.bw_btn.glow.gotoAndStop ("up");
this.loading._alpha = 100;
//here's the problem
var nShot:String=fShot;
return nShot;
}
var nShotBack:String=this.nShot;
this.myloader.contentPath = "gallery/"+ nShot+".jpg";
and then on the thumbnail mc itself I've got this function call:
Code:
on(release) {
_parent._parent.thumbFunction(this._name);
}
What I need is the variable nShot to exist outside the function.
Is it just returning the value of nShot rather than the variable?
This has been driving me mad for days.
|