ActionScript Passing Variable By Value On Reference
It took me hours to figure our why this was returning the wrong value // CODE Samplefunction one(){ var test1 = Array(); test1["one"] = 1; var test2 = test1 trace(test2.one); // output = 1 // this make sense because it gets the value from test1 test1.one = 1000; trace(test2.one); // output = 1000 // !!!! this should be 1}one();/// end CODE SAMPLEFrom the example above You see that in Actionscript when assigning one variable to another it does it my reference not value. So when you chage the value of one array it changes the value of the other automatically.I need to have the "test2" variable reference the "test1" array only by value so if modify "test1" the values of "test2" won't be modified.If this is a setting to change this or a way to have the variable reference only by value this would be extremely helpful.ThanksKJ
KirupaForum > Flash > Flash 8 (and earlier)
Posted on: 12-11-2006, 01:47 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Passing A Variable By Reference?
function foo(bar:Number){
bar = 5;
}
simple example. How do I pass bar by reference to change it's value in the function.
well at least in C++ it's called passing a variable by reference.
[Flash8] Actionscript - Passing Array Variables By Value Not Reference
It took me hours to figure our why this was returning the wrong value - when assigning one array to another it passes by reference not Value. I need a way to force it to pass by values. e.g. copy the existing array and have the second array reference it, so i am free to modify the first array without changing the values of the second
// CODE Sample - show that array assignment = passing by reference.
function one(){
var test1 = Array();
test1["one"] = 1;
var test2 = test1;
trace(test2.one); // output = 1 // this make sense because it gets the value from test1
test1.one = 1000;
trace(test2.one); // output = 1000 // !!!! this should be 1 === passed by reference. If by value this would be independent from test1.one
}
one();
/// end CODE SAMPLE
From the example above You see that in Actionscript when assigning one variable to another it does it my reference not value. So when you chage the value of one array it changes the value of the other automatically.
I need to have the "test2" variable reference the "test1" array only by value so if modify "test1" the values of "test2" won't be modified.
If this is a setting to change this or a way to have the variable reference only by value this would be extremely helpful.
Thanks
KJ
[CS3] Passing Href As A Variable From Javascript To Actionscript GetURL
hello. this question sort of involves actionscript and javascript and i think i've been stuck on this for two weeks now... i dont think i know enough of both to do what i'm trying to do, so i need advice.
i was trying to build a world map in flash with many countries and it is embedded in a javascript page with corresponding links of the country names. when you click on the countryname link, or the country movieclip in flash, it goes to the (hardcoded) url of the individual country page. i nearly died trying to make it work, but now it works beautifully.
but there's only one more problem... what i really want to do is to have the flash file get the url for the country from the html of the page.
what is the best way to have all the urls passed over to actionscript as variables to be used in various getURLs?
all the mcs are neatly named after two-letter country codes, and all the links have ids with the same two-letter country code. for example:
Code:
<A id="NN" href=FicticiousCountry.aspx?PageID=99&CountryCode=NN" onMouseover="asMouseOver(this.id)" onMouseout="asMouseOut(this.id)">FicticiousCountry</A>
i'm not using swfobject to embed my flash file because i somehow could not make it work after writing a lot of code to make the countryname link and the country movieclip light each other up onMouseover. so the solution can't involve swfobject....
i have tried to figure out what i should do, like i tried to read up about writing the urls into an external file, or flashvars (very confusing to me, and i'd have to escape many characters),.. i know its probably not even so complex but i dont know what to do.
can anyone help? or at least point me in some direction?
if anything i've described above is not clear enough i can explain further..
thanks for reading!
Passing Href As A Variable From Javascript To Actionscript GetURL
hello. this question sort of involves actionscript (as2) and javascript and i think i've been stuck on this for two weeks now... i dont think i know enough of both to do what i'm trying to do, so i need advice.
i was trying to build a world map in flash with many countries and it is embedded in a javascript page with corresponding links of the country names. when you click on the countryname link, or the country movieclip in flash, it goes to the (hardcoded) url of the individual country page. i nearly died trying to make it work, but now it works beautifully.
but there's only one more problem... what i really want to do is to have the flash file get the url for the country from the html of the page.
what is the best way to have all the urls passed over to actionscript as variables to be used in various getURLs?
all the mcs are neatly named after two-letter country codes, and all the links have ids with the same two-letter country code. for example:
Code:
<A id="NN" href=FicticiousCountry.aspx?PageID=99&CountryCode=NN" onMouseover="asMouseOver(this.id)" onMouseout="asMouseOut(this.id)">FicticiousCountry</A>
i'm not using swfobject to embed my flash file because i somehow could not make it work after writing a lot of code to make the countryname link and the country movieclip light each other up onMouseover. so the solution can't involve swfobject....
i have tried to figure out what i should do, like i tried to read up about writing the urls into an external file, or flashvars (very confusing to me, and i'd have to escape many characters),.. i know its probably not even so complex but i dont know what to do.
can anyone help? or at least point me in some direction?
if anything i've described above is not clear enough i can explain further..
thanks for reading!
Passing By Reference, Is It Possible ?
Hi, I just wondering is it possible to pass by reference a variable into a function ?? (it means when you change the value of that variable inside the function, it will stay)
I think it works if it's an array but for a simple variable it won't work
Passing A Movieclip Reference
i have a function that i need to pass a movieclip to but it is not working.
when you click on one object it sends another movieclip to the function to move it, i know the function works because i used "this" one time to test it and it moved "this", i just can't get it to move the other object
the function goes
function moveShip(x,y,obj){
obj._x+=x*32;
obj._y+=y*32;
}
the movie clip that uses this function is inside a movieclip but the movie clip that i wish to move is outside of the one containing the call for moveShip
thank you in advance if you are able to help
if you have any further questions which would better able you to help me answer this please ask
Passing A Reference To A Method As A Var
Howdy,
How do I pass a reference to a method as a variable? When instantiating my listBox class, I need to pass it the name of the method(in a different class) I want it to fire when one of it's buttons is pressed.
I'm stumped...
Passing Variables By Reference
Is there a way to pass variables by reference, so something like this:
Code:
var Mytest = "hi ";
function testing(Mytest) {
MyTest += 'world';
}
testing(Mytest);
would make the variable Mytest into "hi world". I tried passing an & (&Mytest) like you do in other languages, but this doesnt work.
Passing An Object Reference
Hey,
If I pass an object reference to a function, create a copy of the object I passed in, and change some of the (new) object's properties (leaving the original unchanged), is that possible ?
no matter what I do, my original object and the new (copy) seem to get changed.
any help would be appreciated. thanks in advance.
Passing A Return Value By Reference
Hello,
I am confused about this. I am returning a value in a class from one method and trying to pass it to another. I know I have done it in C++ in the past, just not sure how to do in in AS3?!?!?
ActionScript Code:
public function CreateImage(event:Event)
{
var image:Bitmap = Bitmap(_loader.content);
trace("this is image " + image);
addChild(image);
return image;
}
public function GetImageSize(image):void
{
trace("this should be the image bitmap " + image);
}
I am trying to pass the object to another method so I can control its properties. Is this even possible? Thanks for any replies.
Passing Parameter As Reference
Hey everybody, do you know if is it possible to pass a parameter to a
class method as a reference and not as a copy? I try to explain, I'm
trying to convert a c++ steering behavior library from c++ to as3, in
c++ you can pass a parameter as reference using & as example if you
call a method getSum(a,b,&result) then in the getSum function the
'result' property of the calling class was set to the sum of a + b. I
hope you understand what I mean.
There is a way to do this in as3?
thank you
Passing Arguments By Reference
Hi,
I have a really simple question about AS: Is it possible to pass arguments "by reference" instead of "by value". I know it's possible in almost every programming/scripting language I came across until today, but I didn't find any hint for doing it in Actionscript
For those who don't know what "by reference" means: If you want to pass a Number to a function, say
Code:
var mynumber:Number = 5;
calculate(mynumber);
and you change the value of the argument inside the function, e.g.
Code:
function calculate(num:Number) {
num += 1;
}
then the call to calculate normally does NOT change the value of mynumber because you have passed mynumber "by value", which means the value of mynumber has been copied to the num argument. This means mynumber is 5 all the time.
Now sometimes u want to be changing arguments given to a function inside the function, and this is where u will normally use references. Passing mynumber "by reference" would mean that after calling calculate the value of mynumber will be 6...
I know complex Objects like MovieClips are passed by reference. But how to do it with simple DataTypes like Number, Boolean etc.???
Passing Arguments By Reference
Hi,
I have a really simple question about AS: Is it possible to pass arguments "by reference" instead of "by value". I know it's possible in almost every programming/scripting language I came across until today, but I didn't find any hint for doing it in Actionscript
For those who don't know what "by reference" means: If you want to pass a Number to a function, say
Code:
var mynumber:Number = 5;
calculate(mynumber);
and you change the value of the argument inside the function, e.g.
Code:
function calculate(num:Number) {
num += 1;
}
then the call to calculate normally does NOT change the value of mynumber because you have passed mynumber "by value", which means the value of mynumber has been copied to the num argument. This means mynumber is 5 all the time.
Now sometimes u want to be changing arguments given to a function inside the function, and this is where u will normally use references. Passing mynumber "by reference" would mean that after calling calculate the value of mynumber will be 6...
I know complex Objects like MovieClips are passed by reference. But how to do it with simple DataTypes like Number, Boolean etc.???
[Flash 8] Passing A Reference With The Mouse
I'm quite new at Flash, so please indulge me if this is a silly question. I have been wanting to implement a method which requires that one instance on the stage is passed as a reference to another instance on the stage when clicked on.
Specifically, I've programmed a context menu for mySymbol with the option "link to another mySymbol", which when selected should allow the user to mouse-click another mySymbol instance on the stage to which he wants to link. The reference for that item should then be stored within the original mySymbol instance. Btw, I'm trying to do all of this through external .as class files, if that makes any difference.
I've tried to think long and hard about how to this but have no idea how to even start going about it. Any help would be greatly appreciated.
Thanks.
Passing Mc By Reference Into A Draw() Method
Code:
var bitmapMC:BitmapData = new BitmapData(SW, SH, true, 0xFFFFFFFF);
var mcreference:MovieClip = holder[holdername];
bitmapMC.draw([mcreference]);
I'm trying to pass an mc by array reference into a BitmapData.draw method.
The code above seems to work only when I replace the [mcreference] with a movieclip that is on the stage; holder.holder_mc1 for example.
Am I not passing/typing the variable correctly, or is this a bug in Flash 8? (Currently, the mcreference "variable" is typed as an MC.)
Thanks for any help!
Problem Passing Variable Values (from XML) To Variable In Child Movie
I'm reading something from XML, and store it in a variable. I can trace the variable and it shows two items. I can display those two seperately with variable[0] and [1], meaning that it works as intended.
After that, I'm calling a movieclip, which is supposed to read that variable.. sadly, it can't do it. So I resorted to passing the content of the first variable to a variable inside the called movieclip. This works, and tracing the second variable shows both items from the first. However, I cannot access the items seperately with variable2[0] for example.
What's the problem? The second variable is currently a string. I tried to declare is as other things (like xml or array) as well, but that didn't help. Is there also a way to make this procedure unnecessary, i.e. can I somehow access the first variable?
I've attached the fla/xml/swf in case my description doesn't make sense!
Reference Variable On MT From Mc How?
Hi everyone,
A little brain fart here: I have some input text set to variable 'speed' on the main timeline.
I have an instance of an MC also on the maintime line. I have attached a enterframe action the mc and wish to reference the speed variable. I thought it woud be:
_x += _root.Number(speed);
but it's not working . Why?
Thanks if anyone could help. Would really appreciate!
j
Reference Mc With Variable Value
i have a variable containing the name of a mc i want to play.
so instead of...
home.gotoAndPlay(6);
home being the mc instance.
i have...
_root.current_selection == "home";
so how do use _root.current_selection instead of 'home' in the above statement?
Cheers guys,
Robsco!
Using A Variable To Reference A Mc
I want to reference a movie clip with a variable.
ie.
var section;
section = "red";
section.gotoAndStop("one");
This doesn't seem to work when the movie clip is called red.
Is there some specific syntax for this? Do I need to dereference the variable?
thanks.
Using A Variable In MC Reference.
I am trying to use ActionScript to create text fields and then add text to them.
So I have
Code:
for ( i = 0; i < 10; i++)
{
var textName = "mytextfield"+i;
this.createTextField(textName, 10, 10, 10, 450, 80);
textName.text = "This text isn't working";
}
Can you help me on how make it so that create 10 instances?
Variable Reference Problem..
Hi.. I really need some help please..
I am loading a variable from an external text file, the variable is called text. I can set this as the variable for a dynamic text field and it will work ok, but I can't access it elsewhere. I want to access it in a for loop like so and find it's length:
for (i=1; i < length(_root.text); i++)
but it won't access it, let alone find it's length..
I can't even assign a variable like
test = _root.text or test = _level0.text , this is on the 1st frame of the main scene so I don't see why there should be any problems.. any ideas?
Any help would be really appreciated..
Thanks
LoadMovie -> Variable Reference
Hi,
I am building a wrapper file to loop a bunch of SWFs I have. The wrapper file loads an XML file within which the user can specify which SWFs they want to include in the loop. However, I need to limit them from specifying any kind of SWF, so in my target SWFs I have a "checksum" variable. I want to be able to verify that checksum in the wrapper to make sure its a valid SWF to load.
So, here's what I did, but it didn't work (as I had expected but I tried anyway):
<code>
loadMovie("blah.swf", targetMC);
targetMC.stop();
checksumValidationInterval = setInterval(validateChecksum, 0);
function validateChecksum()
{
if (targetMC.getBytesLoaded() > 4 && targetMC.getBytesLoaded() >= targetMC.getBytesTotal())
{
clearInterval( checksumValidationInterval);
if (targetMC.LOOP_CHECKSUM == this.LOOP_CHECKSUM)
{
&n bsp;targetMC.play();
}
else
{
&n bsp; // Display the error message
&n bsp; errorString = "'" + movieList[movieTracker].source + "' is an invalid SWF!";
&n bsp; gotoAndPlay("errorDisplay");
}
}
}
</code>
Is this even possible and I'm just doing it the wrong way, or is this impossible to do? Any idea anyone?
Variable From Embed Tag...how To Reference It
Not quite sure how to reference a variable sent to flash from the snip from the flash html code below:
PARAM VALUE="/_template/nav2003.swf?section=webcams
EMBED src="/_template/nav2003.swf?section=webcams"
I thought it would load into the _root level, but it's not found. I'm trying to load a movie in to an empty mc on the main timeline...I've tried onClipevent and a fram action to loadMovie but have not had any success. Any suggestions?
Thanks!
How To Reference A Variable Within A Loaded SWF
hi,
if i load a SWF into my main movie using loadMovie or loadMovieNum, how do i them reference that SWF in my actionscript from the main movie or another loaded SWF?
for example, let's say i load subMovie.swf into my main movie, and i subsequently want to check a variable subMovieVar that resides in subMovie.swf from my main movie actions layer.
i tried _root.subMovie.subMovieVar, but it didn't work.
i also tried loading subMovie.swf into a container MC using loadMovie("subMovie.swf", "container") and then referring to the variable as _root.container.subMovieVar, but again, no luck.
i know this must be a really stupid question, but does anyone know?
thanks.
Variable Reference Problem
Can anyone help me with this variable problem I'm having? In the first part of the code below, I'm setting some text from an XML document to the variable "caption", which seems to be working fine. The trace shows this is working.
Later in the code (under the if(count==1){}) I try to reference all those variables that have been assigned to the MCs (pic1_mc, pic2_mc, etc) and I cannot seem to get it tto work. The trace comes up empty. Am I missing something here?
code:
function loadImages() {
loadStage=0;
count=1;
this.onEnterFrame=function(){
if(loadStage==0){
_root.createEmptyMovieClip("pic" + count + "_mc", theDepth--);
_root["pic" + count + "_mc"].caption = passItOn.childNodes[count-1].firstChild.firstChild;
trace("captionMC = " + _root["pic" + count + "_mc"].caption);
_root["pic" + count + "_mc"].loadMovie("images/pic" + count + ".jpg");
loadStage=1;
}
else if(loadStage==1){
BL=_root["pic" + count + "_mc"].getBytesLoaded();
BT=_root["pic" + count + "_mc"].getBytesTotal();
//trace("BL / BT : pic" + count + "_mc = " + BL + " / " +BT);
_root.tracing = BL;
if(BL >= BT && BL >0){
offsetYButtons += 20;
if(count==1){
_root["pic" + count + "_mc"]._alpha = 100;
_root["pic" + count + "_mc"]._x = 150;// set the clip's _x to 150
_root["pic" + count + "_mc"]._y = 55;// set the clip's _y to 55
_root.currentImage = 1;
captionTemp = _root["pic" + count + "_mc"].caption;
trace("caption1 = " + captionTemp);
_root.captionField = captionTemp;
loadButtons();
}else{
_root["pic" + count + "_mc"]._alpha = 0;
_root["pic" + count + "_mc"]._visible = false;
_root["pic" + count + "_mc"]._x = 150;// set the clip's _x to 150
_root["pic" + count + "_mc"]._y = 55;// set the clip's _y to 55
loadButtons();
}
count++;
loadStage=0;
}
}
if(count>duplicate){
delete this.onEnterFrame;
}
}
}
Thanks in advance
Erik
How Do I Get The Object Reference Of A Variable?
I have a few long named variables with long paths.
Can someone tell me how I can create a new short name variable and assign it to the reference of the long named variable?
Erm... perhaps I'm not being clear.
I have the following variable say:
myMovie.anotherMovie.holdingMovie.myVariable
I want to create another variable called:
shortVar
When I change the second, I want this to change the value of the first as well because in memory they point to the same variable stored in memory.
Hmmm does that make any sense?
Any help would be appreciated.
Thanks.
OM
String As Reference To Variable
I've been trying for weeks to find a way to use the string "OSL" point to my variable _root.OSL which is an array.
I've searched google in all the ways I can think of whit no result exept one which was about macromedia director. In director you could write something like _root["OSL"] to access the variable _root.OSL
Is it possible to do something like that in flash?
Thanks
Reference To Variable Not Correct?
Hi,
I'm trying to play a certain frame of a movieclip loaded on the timeline when a value increases or decreases.
I have this function that does this:
code:
// check if value was up or down
function upDown(varCheck:String, oldval:String, newval:String, txtField:MovieClip) {
// value is different
if (newval != oldval) {
// change value
txtField.text = newval;
// if new value is lower than original, show red
if (newval<oldval) {
trace("Variable "+varCheck+" has decreased to "+newval+" from "+oldval);
txtField_upDown.gotoAndStop("red");
colourChange(txtField, 0xFF0000, 0xFFFFFF, bold);
// if new value is higher than original, show blue
} else if (newval>oldval) {
trace("Variable "+varCheck+" has increased to "+newval+" from "+oldval);
txtField.toString();
txtField_upDown.gotoAndStop("blue");
colourChange(txtField, 0x0000FF, 0xFFFFFF, bold);
}
return newval;
// value not different, set to default colours
} else if (newval == oldval) {
colourChange(txtField, 0xFFFFFF, 0x000000, normal);
return newval;
}
}
Notice the line txtField_upDown.gotoAndStop("blue");
If I actually type the name of the text box instead of using a variable it works absolutely fine - it's just passing the variable txtField to that line that is causing me problems I think.
This is that function being called:
code:
watch("volume", upDown, volume_txt);
Any ideas what I'm doing wrong?
Cheers,
Chris
Setting A Variable Via A Reference
I've got a function that returns a reference to a variable, given the variable's name as a string. (Don't ask, there's a good reason.) The variables are elements in a structured object. (i.e. cmi.core.lesson_location, cmi.core.score.raw, etc.)
The problem I'm having is trying to figure out how to set that variable if I have a reference to it stored in another variable.
PHP Code:
private function getElementRef(eName:String):Object {
var subElements:Array = eName.split(".");
var currentElement:Object = applicationCMI;
// applicationCMI is a reference to the instance
// of the data object that has all the variables
for (var i:Number = 1; i<subElements.length-1; i++) {
currentElement = currentElement[subElements[i]];
}
return currentElement[subElements[subElements.length-1]];
// yes, I'm intentionally skipping over the first item of subElements
}
var newData = "hello world";
var x = getElementReference("cmi.core.lesson_location");
x = newData;
Obviously, this just sets the variable x to the value of newData.
I'm trying to separate out the bit of code that loops through the cmi instance, so I can use it in both a getter and setter method without having the same code in 2 places.
If I put the same code in both functions I can just use:
code: currentElement[subElements[subElements.length-1]] = "blah";
directly in the setter method because I'm targeting a variable by name from a reference of an object. I'd like to avoid duplicating the looping code though.
The reason for the function is that the complexity of the cmi object can change. I have variables ranging from cmi.suspend_data to cmi.core.lesson_status to cmi.core.score.raw to cmi.blah.blah.blah[n].blah etc.
How To Reference Clips With More Than One Variable In Name?
Hi, I have a script with mutilpe loops and I need to be able to access an object that's created dynamically with more than one variable... is this possible?
For example, say I have a clip on the root like this: _root.clip1.clip2
I need to access that with variables, like this:
root[var1][var2]
but that's not working for me.
Any ideas?
[F8] Variable Reference Issue
Ok here is the problem. I have code which stores a reference to the base object in a class for reference from code later. The problem is when I call my function (TestFunction) the first trace returns [object Object] like it should, but the second trace (inside the xml.onLoad function) returns undefined. I am sure this is a scope issue. If somone could shed some light on this for me that would be great. Thanks a lot in advance!
Code:
var m_base = null;
// DATA STORAGE
public static var m_makes : Array = new Array ();
// INITIALIZATION FUNCTIONS
function FWDataComponent(listenObject:Object)
{
m_base = this;
}
// DATA FUNCTIONS
public function TestFunction() : Void
{
trace(m_base);
var xml : XML = new XML ();
xml.ignoreWhite = true;
xml.onLoad = function ()
{
trace(m_base);
var nodes = this.firstChild.childNodes;
m_makes = new Array ();
for (var i = 0; i < nodes.length; i ++)
{
m_makes.push (nodes [i].firstChild.toString ());
}
}
xml.load (m_serverPath + "GetMakes");
}
[F8] Variable Content Reference, Help?
I have an input text field with a var name of 'input_email'. In my code how do I reference 'input_email' correctly in order to reference its content, please see the script below:
Code:
on (release) {
if (input_email ne "") {
sendvariable = "http://zarthsan.com/work/spy_test.php?email=" + input_email + '&action_type=register&newsletter=Y';
getURL(sendvariable,'_self');
}
}
+ input_email + is where Im trying to reference the 'input_email' content which in turn will be sent along with the rest of 'sendvariable'...
An ideas? Am I going about this sideways? Thanks for any help.
Dynamically Reference Variable?
Is it possible to reference a variable by constructing its name by combining other vars or vars +strings? For example, in the snippet below, can I get the value of childA_X in the trace statement by constructing its name from the current array element plus the string "_X"?
PHP Code:
var mcArray:Array = new Array("childA", "childB");
var childA_X:Number = childA._x;
for (var index in mcArray) {
switch (mcArray[index]) {
case "childA" :
trace("childA Original Posn: "mcArray[index]+_X);//Fails of course
...
I've run into this type of thing a few times and have never figured out how to do it. Maybe it isn't possible?
Thanks.
Mitch
Using Variable To Reference An Instance Name
I've got a problem with a function that I've written. Here's the function:
//Dims inactive nav items
function dimNav(active, Title) {
_root.Content.Title.text = Title;
for (i=0; i<myArray.length; i++) {
var buttonName:String = "btn_"+myArray[i];
if (myArray[i] == active) {
//_root.btn_photos._alpha = 100;
_root.buttonName._alpha = 100;
_root.btnName.text = buttonName;
} else {
//_root.btnName2.text = "not";
_root.buttonName._alpha = 80;
}
}
}
The purpose is to dim the rest of the items after you choose an area. The lines in red above don't work, but if you manually type in the instance name (see green line) of the button, it works. What am I missing?
Change Value Of Variable Through Reference
Hi,
I am writing a Console class, of which one specification is that the user can modify variable values.
In the Console I keep track of a list of items, which represent possible commands. An item looks like this
Code:
// Item.as
package {
public class Item {
public var name:String;
public var description:String;
public var type:uint;
public var any:*;
}
}
// Console.as
package {
public class Console {
private var mItems:Array;
public function Console() {
mItems = new Array();
}
public function addItem(item:Item):void {
mItems[item.name] = item;
}
public function parseCommandLine(commandLine:String):void {
var args:Array = commandLine.split(" ");
// Checking code omitted
var item:Item = Item(mItems[args[0]]);
if (item.type is String) {
if (args.length == 1) {
// Read
trace(String(item.any));
} else {
// Write
// This sets only item.any to the given args[1],
// but not the value of the variable item.any should
// reference
item.any = args[1];
}
}
}
}
}
Code:
var username:String = "";
var console:Console = new Console();
console.addItem(new Item("username"), "Name of the user currently in the session", 1, username);
The user gives a command as follows
Code:
username John
What this command should do is setting 'username' to 'John', but the code above only sets item.any to 'John'. It seems pass by value is used in the case of uint, int, Number, Boolean, String. How can I set the username variable to the given value (which would be the case if pase by reference would have been used)?
Cheers!
Jorrit
Variable Reference Instance Name?
I was wondering if there was a way for me to have it so a variable references an instance name of a movie clip.
Here is a quick example of basically what I want to do
ActionScript Code:
function Ogremove(OgreName){
Ogrename._x+=1
}
onEnterFrame=function(){
Ogremove(Ogre1)
Ogremove(Ogre2)
}
I plan on using this for a very basic AI where I want all of the monsters to act in the same way, but not do the exact same thing (though my example doesn't show this, I just wanted to simplify it as much as possible).
How Can I Reference A Variable In A Url Address?
i have a variable called url
and one button which needs
getUrl (http://www.allways.com/my variable url
i have tried to reference this variable but with no success
any help would be appreciated
thanks Mat
Variable Reference Of Instance Name
While I have had no problems with bracket evaluation of constants and number variables, I don't know the coding convention for brack evaluation of a string.
I get an undefined for oBtnName
oBtnName = new Object;
oBtnName = this["mcWing" + aWingColor[nIdx] + "Btn"];
where aWingColor is an array of strings. So I tried setting aWingColor[nIdx] to variable thinking the inside array brackets were goofing this up:
oBtnName = new Object;
var sWingColor:String = aWingColor[nIdx];
oBtnName = this["mcWing" + sWingColor + "Btn"];
trace (sWingColor + " " + oBtnName._name );
returns Pink undefined
and interactive debug is showing oBtnName as undefined as well.
So, then I tried this
oBtnName = this["mcWing" + sWingColor._value + "Btn"];
and then this
oBtnName = this["mcWing" + "[sWingColor]" + "Btn"];
and so on and so on. . . .
[AS3] Reference To Stage Variable From MC
Hi!
At the begining I'm sory for my English ;)
I've been coding in AS2 for a while, but now I decided to try AS3. The situation is like:
- I've got one Movie Clip on a stage
- I have a code in the 1st frame of the Main Timeline:
var somevar:String = "somevalue"
- I have a code in the 1st frame of the Movie Clip's timeline:
trace(root.somevar) // error
trace(parent.somevar) // error
How to trace that variable?? The same is with stopping the Main Timeline's playback.
parent.stop() and root.stop() don't work :(
HEEELLLP MEEE! ;)
Reference Movieclip Through A Variable?
I am trying to fadeout the image loaded origninally, but I can not get a reference to it. Any help would be appreciated.
Attach Code
this.pArray = new Array();
this.mcArray = new Array();
for (i=0; i<this.picCount; i++) {
this.pArray[i] = i+1+".jpg";
this.mcArray[i] = "hero_mc"+(i & 1);
}
this.fadeSpeed = 4;
this.pIndex = this.beginPic-1;
loadMovie(this.pathToPics+this.pArray[beginPic-1], this.mcArray[beginPic-1]);
setInterval(this, "changePhoto", 6000);
MovieClip.prototype.changePhoto = function() {
if (this.pIndex>=this.pArray.length-1) {
this.pIndex = 0;
}
else {
this.pIndex++;
}
this.onEnterFrame = fadeOut;
};
MovieClip.prototype.fadeOut = function() {
if (this.mcArray[pIndex-1]._alpha>this.fadeSpeed) {
this.mcArray[pIndex-1]._alpha -= this.fadeSpeed;
}
else {
this.loadPhoto();
}
};
Is It Possible To Use AttachMovie With A Variable ID Reference?
Hello:
I am trying to write an attachMovie statement with a variable feeding the ID parameter. Is that possible?
For Example:
fadeInVar = '"LS_body_home_ID"';
_level0.LS_hitArea_body.attachMovie([fadeInVar], "attached_LS_body", 1);
I can't quite figure out how to write this. I tried an eval function as well...
If you have any ideas, please let me know.
Thank you!
- Garrett
|