0
New Here
,
/t5/animate-discussions/object-reference-pointer/td-p/113294
Aug 05, 2008
Aug 05, 2008
Copy link to clipboard
Copied
Hello,
I have a 'main' which dynamically creates objects from a custom class at runtime. The user can then change the properties of these objects on the stage. e.g. text, color, alpha.
My problem is that when I try and change a property of one object, such as text, every object created from that class changes in the same manner.
What is the best way of referencing one particular object that I have created and added to the stage, either by passing a reference/pointer to 'main' or using some kind of flag to remember which object or another method etc.
I have just realised that the way I create each object is "var objectName:MyClass = new MyClass();" in a function which is called when an 'add' button is clicked. So I need to differentiate between these MyClass objects which have the same name (declaration).
Thank you in advance,
I have a 'main' which dynamically creates objects from a custom class at runtime. The user can then change the properties of these objects on the stage. e.g. text, color, alpha.
My problem is that when I try and change a property of one object, such as text, every object created from that class changes in the same manner.
What is the best way of referencing one particular object that I have created and added to the stage, either by passing a reference/pointer to 'main' or using some kind of flag to remember which object or another method etc.
I have just realised that the way I create each object is "var objectName:MyClass = new MyClass();" in a function which is called when an 'add' button is clicked. So I need to differentiate between these MyClass objects which have the same name (declaration).
Thank you in advance,
TOPICS
ActionScript
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
1 Correct answer
Community Expert
,
Aug 06, 2008
Aug 06, 2008
or you could use a property of your class items like the
displayobject uses the "name" property, so you could retrieve
objects using their property.
Community Expert
,
/t5/animate-discussions/object-reference-pointer/m-p/113295#M2489
Aug 05, 2008
Aug 05, 2008
Copy link to clipboard
Copied
are you using a static property? that's about the only thing
that would cause them all to change. otherwise, using a setter
would be a typical way to change the properties of individual
instances.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
BadFortune
AUTHOR
New Here
,
/t5/animate-discussions/object-reference-pointer/m-p/113296#M2490
Aug 05, 2008
Aug 05, 2008
Copy link to clipboard
Copied
Hi,,, I'm not using static properties within the class. Class
variables are defined as below. I've set all the class variables
public so i don't have to use setters (for the moment).
public var meters:int = new int(600);
I think i might be getting into trouble because I can't reference an individual object? If the user clicks on a movieClip on the stage, I need to know which object it belongs to so that i can then change its instance properties.
I am only using one line/name to create multiple objects ( as below ). Is this wrong/impossible for me to reference the way i need to? How else might i reference a screen item to its particular object?
var myObject:MyClass = new MyClass();
Thank you.
public var meters:int = new int(600);
I think i might be getting into trouble because I can't reference an individual object? If the user clicks on a movieClip on the stage, I need to know which object it belongs to so that i can then change its instance properties.
I am only using one line/name to create multiple objects ( as below ). Is this wrong/impossible for me to reference the way i need to? How else might i reference a screen item to its particular object?
var myObject:MyClass = new MyClass();
Thank you.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/animate-discussions/object-reference-pointer/m-p/113297#M2491
Aug 05, 2008
Aug 05, 2008
Copy link to clipboard
Copied
i have no way to know the relationship between a MyClass
instance and a movieclip on stage.
are all your MyClass instances names myObject? if so, and you want to address the various MyClass instances, you've got a problem
are all your MyClass instances names myObject? if so, and you want to address the various MyClass instances, you've got a problem
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
BadFortune
AUTHOR
New Here
,
/t5/animate-discussions/object-reference-pointer/m-p/113298#M2492
Aug 06, 2008
Aug 06, 2008
Copy link to clipboard
Copied
yes... all the class instances have the same name eg.
myObject, but when the user clicks on a movieclip which belongs to
a particular object, i want to know which object it belongs to so i
can change its other settings. Unfortunately all objects are
created with...
var myObject:MyClass = new MyClass(); // ( all with same name myObject )
Is there any way of identifying the particular object that the movieclip belongs to, or will i have to change my implementation? If so how might I create dynamic names when the user chooses to create an object?
Thank you.
var myObject:MyClass = new MyClass(); // ( all with same name myObject )
Is there any way of identifying the particular object that the movieclip belongs to, or will i have to change my implementation? If so how might I create dynamic names when the user chooses to create an object?
Thank you.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

/t5/animate-discussions/object-reference-pointer/m-p/113299#M2493
Aug 06, 2008
Aug 06, 2008
Copy link to clipboard
Copied
There are a few things you can do:
1. You can push each newly created object into an array, where you can target them individually later.
var myObject:MyClass = new MyClass();
var myObjectArray:Array = [];
myObject.addEventListener(MouseEvent.CLICK,changeMyObject);
myObjectArray.push(myObject);
function changeMyObject(e:MouseEvent){
for(var j=0;j<myObjectArray.length;j++){
if(myObjectArray == e.target){
//change properties of said object
}
}
}
2.You can create mimic creating dynamic instance names (although you lose strict typing capabilites)
//assuming this code is on the root timeline
for(var i=0;i<5;i++){
this["object"+i] = new MyClass();
}
for(var objs in this){
trace(objs)
}
3. If you're creating the class on an object of sorts create a reference to it:
var myContainerThing;
myContainerThing.customClass = new MyClass();
Hope that makes sense and/or helps.
Cheers,
FlashTastic
1. You can push each newly created object into an array, where you can target them individually later.
var myObject:MyClass = new MyClass();
var myObjectArray:Array = [];
myObject.addEventListener(MouseEvent.CLICK,changeMyObject);
myObjectArray.push(myObject);
function changeMyObject(e:MouseEvent){
for(var j=0;j<myObjectArray.length;j++){
if(myObjectArray
//change properties of said object
}
}
}
2.You can create mimic creating dynamic instance names (although you lose strict typing capabilites)
//assuming this code is on the root timeline
for(var i=0;i<5;i++){
this["object"+i] = new MyClass();
}
for(var objs in this){
trace(objs)
}
3. If you're creating the class on an object of sorts create a reference to it:
var myContainerThing;
myContainerThing.customClass = new MyClass();
Hope that makes sense and/or helps.
Cheers,
FlashTastic
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/animate-discussions/object-reference-pointer/m-p/113300#M2494
Aug 06, 2008
Aug 06, 2008
Copy link to clipboard
Copied
or you could use a property of your class items like the
displayobject uses the "name" property, so you could retrieve
objects using their property.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
BadFortune
AUTHOR
New Here
,
/t5/animate-discussions/object-reference-pointer/m-p/113301#M2495
Aug 06, 2008
Aug 06, 2008
Copy link to clipboard
Copied
quote:
Originally posted by: kglad
or you could use a property of your class items like the displayobject uses the "name" property, so you could retrieve objects using their property.
Ok, Thank you very much for the posts so far.
I've stuck the objects in an array and given them 'name' variables (strings).
This may be a stupid question, but is there a good naming convention i can use? This is because i don't know how many objects will be created at runtime. Would it be best to just numerate names? i.e. name1, name2, name3 etc.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
LATEST
/t5/animate-discussions/object-reference-pointer/m-p/113302#M2496
Aug 06, 2008
Aug 06, 2008
Copy link to clipboard
Copied
yes, use something like myClassInstance1, myClassInstance2,
etc that makes it obvious what those instances are even if you
re-check this application a few years after you finish it.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

