ActionScript 3.0 :: Objects Pass By Reference?
Mar 16, 2012var obj:Object = null;
recursionTest(0, obj);
trace("obj: " + obj);
[Code].....
var obj:Object = null;
recursionTest(0, obj);
trace("obj: " + obj);
[Code].....
I have this really simple actionscript function and for the life of me i cannot figure out the correct way to pass in the frame reference name![code]
View 4 RepliesHow can I pass parameters by reference? So it doesn't make a copy out of it, but modifies whatever I pass in? This:
function ChangeString(string:String)
{
string = "inside string";[code].....
outputs "outside string", since functions seem to take objects by value. get multiple variables out of functions? Returning a custom class?
i want to pass by reference so i can use this variable outside the function.
What im doing is creating a global variable such as var cont:int; and then in a eventListener like enter_frame (stage.addEventListener..) calling a function called "mover", this function modifies "cont" value and i just want to print this value modified. The issue is i cant pass the value by reference just by const :S. The function is void, but if i change it to return int, its useless because each time i call the function, the value i want to return its created each time with a new value, beacuse i need to declare it so.. I read i can use a var such as Object but i really dont get it (im used to c++ i have to say)
I have Mac OS widget with flash. If to click on flash the URL in a window of a browser should open. But it does not occur. I use code like this:
DETAILS_HTML='object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="700" height="460" id="start" align="middle">'+
'param name="allowScriptAccess" value="always" />'+
'param name="flashvars" value=SomeParam>'+
[code]....
How do I pass values by reference inside a for each construct in AS3? Basically, I want something equivalent to the following code in PHP:
foreach ($array as &$v) {
$v = $v + 1;
}
This would allow me to change all elements of the collection $array through a single loop.
I'm new to AS3 and I was making a game of chess. Basically whenever you click a square with a chess piece, I assumed it would be like java, and you'd be able to create an "ActionListener" that would pass a reference to a square that was clicked.
My question is this: How can I access this square object that was clicked in my array?[code]...
In AS2 I have several arrays constructed like this :
var myArray0:Array=new Array(value,value,value...)
var myArray1:Array=new Array(value,value,value...)
var myArray2:Array=new Array(value,value,value...)
var myArray4:Array=new Array(value,value,value...)
...
What I'm trying to do is use iteration to reference each array name to pass it into a function.
Like :
function doSomethingWithArray(arrayToPass){
...
}
//Later somewhere in For loop... :
_root["myButton"+i].onRelease=function(){
doSomethingWithArray(WHAT-THE-HELL-I-TYPE-HERE[i])
}
I have this code:
var service:HTTPService = new HTTPService();
if (search.Location && search.Location.length > 0 && chkLocalSearch.selected) {
service.url = 'http://ajax.googleapis.com/ajax/services/search/local';
service.request.q = search.Keyword;
[Code]......
I want to pass the search object to the result method (onServerResponse) but if I do it in a closure it gets passed by value. Is there anyway to do it by reference without searching through my array of search objects for the value returned in the result?
I have 2 arrays, let's just say aSubArray and aMainArray. I set the values for aSubArray then use aMainArray.push(aSubArray); When I go to change the values for aSubArray, in the case of a for loop, all references in aMainArray are changed. How can a pass the values of aSubArray to aMainArray rather than just a reference?
View 1 RepliesI'm trying to do something like this, but for some reason it isn't working...
Code:
function mouseClickHandler(t:MovieClip):Void
{
if(!t){
[Code]....
Hmm, I replicated this situation in a blank movie and it works as it should.
when to use this in a classes?is there any specific rule?is it wrong to use this when you want to just access the stage that way?or is it better to pass the reference to the stage in the class constructor?
View 5 RepliesIn AS2 I have several arrays constructed like this :
var myArray0:Array=new Array(value,value,value...)
var myArray1:Array=new Array(value,value,value...)
var myArray2:Array=new Array(value,value,value...)
var myArray4:Array=new Array(value,value,value...)
...
What I'm trying to do is use iteration to reference each array name to pass it into a function.
[Code]...
In a game me and a friend is creating, the levels are stored in MCs.In the level MCs there are several other MCs that the player should be able to interact with.
This means the objects in the levels need a stage reference.I can place all the objects manually and pass the stage ref in the constructor of the object's class, but this is a pain when the levels are going to be pretty big.
Is it possible to make sure that flash always passes a stage ref to the object even though it's not placed there by code?
I want to be able to call a JavaScript function from a Flex app using ExternalInterface and pass a reference to a different JavaScript function as an argument.
[Code]....
I'm unsuccessfully attempting to instantiate a reference of a class that is passed as a parameter to another class. In this example there are 3 classes:
MainClass, Canvas, MyCircle
From the MainClass I am creating an instance of Canvas, which is passed a class reference of MyCircle as I want to create instances of MyCircle from within Canvas. However, the MyCircle constructor contains required parameters that are created from within Canvas. How can I pass and instantiate a class reference with required parameters?
MyCircle:
package {
//Imports
import flash.display.Shape;
//Class
public class MyCircle extends Shape {
[Code] .....
[Code]...
I've learned it reading a tutorial over internet, but I want to know where I can find more samples on how to reference objects in AS3. For future codes, I want to add hitTest and the like.
How do you guys reference one of multiple objects? Every recent project of mine winds up having a bunch of items pushed into an array, and I find out which one to manipulate like this:
Code:
function myFunction():void
{
index = e.target.name.slice(5,7); // object is named "item_1"
myArray[index].x += 5 (or whatever);
}
How can i reference objects on stage so i can push them into an array using a loop?[code]...
View 2 RepliesI am creating a generic button that will remove items created dynamically in a movie clip container from memory (not just from the display list).
To track which item the user has selected for deletion, I have a click function that stores the name of the clicked object in a variable called objName. I then store a reference to the object itself in another variable called targetObj. I can then easily remove the object from the stage like this[code]...
How do you refer to specific named instances of objects (buttons, movie clips, text fields, etc.) in different scenes? I made two scenes with button1 on scene 1 and button2 on scene 2. My code is below. The button2.addEventListener line gives the error "cannot access a property or method of a null object reference." Removing that line removes the error and button1 switches scenes. What's the proper way of referring to button2?
package
{
import flash.events.Event;
import flash.events.MouseEvent;
[code]....
I want to loop through an array of map tile coordinates, place a tile on the stage for each coordinate, and put a reference to each tile instance in a separate multidimensional array called mapRef, where the tile instances can later be referenced by their coordinates in mapRef. Is this line (excerpt from the code below)... Main.mapRef[i][j] = mapTile;.[code]
View 3 RepliesI want to a framework to pass objects between Java and AS3 using sockets. It should be something with good performance (not XML, JSON). I have looked into AMF but all of the tutorials are very complex and not about what I need. I have used java to java serialization but I can't find any tutorial about Java to AS3.
View 4 RepliesWhat is the recommended way of passing objects into the eventhandlers of a Loader?
var l:Loader = new Loader();
var o:Object = new Object();
l.tag = o; // i imagine something like this
[Code]....
I was wondering about which is the best method to use when passing variables to a class. So if I were making a complex class which required many variables to be passed/set to function [code]...
To date have used method #1, but I guess I lean toward method #2 although my inexpierience has me majorly doubting that and was wondering if anyone else had any views on this?
I am trying to dynamically add to the targetpath of objects that I pass into a function. I am not sure if this can be done but the following code kinda explains best what I am trying to do.
Code: Select allvar mc1:MovieClip = new MC();
var mc2:MovieClip = new MC();
var arr:Array = new Array(mc1, mc2);
[Code]....
So mc1 and mc2 are both created by objects that are instantiated from library. It contains nested children "mc2.mc3.textField". How I might be able to dynamically refer to the path of a MovieClip
I am trying to add some Sprite objects as the contents of an array, and I would like to be able to "clear" them from the stage. I would assume that if there are loaders involved, I need to do
_imgArray[i].close();
_imgArray[i].unload();
And if I am using a sprite, I can do:
removeChild(_imgArray[i]);
None of the above work.
Currently I try:
for(i = 0; i < _localXML.length(); i++) {
var tmp:BMLink = new BMLink(_localXML[i], _bw, _bh, i);
_imgArray[i] = tmp;
_imgArray[i].x = (_bw + _mainpad) * i;
_base.addChild(_imgArray[i]);
But this doesn't work.
The class instances that are populating the array are all extending sprite, but they have their own individual loaders inside w/ progress events etc.
I'm doing an geometry object tranformations for a project. I need to have same rectangle across 4 parts in a screen. So when i change one rectangle others will be transformed like scaling or something.So i was able to do this with image, just giving "source" attribute. How to do with geometry objects?[code]
View 1 RepliesThe documentation on parameters for application.onConnect() is below. It can take a Client "object" but is ambiguous about the optional parameters (strings vs objects). I'm guessing just strings?
I have a user value object with a few pieces of info in it that I pass around client side and would like the server to add it to its list of users (usersSO). I'm guessing I'll have to send it up in pieces and recreate it somehow on the server?
ParametersclientObjA Client object. This object contains information about the client that is connecting to the application.p1 ..., pNOptional parameters passed to the application.onConnect() handler from the client-side NetConnection.connect()
Is it possible to pass constructor arguments to instance objects which I place on the stage? Are the instantiations of instance objects centralized somewhere as with .NET WinForms so I can just edit the xxx = new CustomRecangle() constructor?
public class CustomRectangle extends MovieClip {
public function CustomRectangle(width:int, height:int) {
this.width = width;
this.height = height;
}
}