Accessing Class Objects Instance Name
Hello I have a class name Contents I am creating 5 objects of this class. Is there a way to keep track of the instance names assigned to the objects. What I am doing is get all the objects of Contents class and make button out of these and when user clicks a button the I want to reterieve descrioption from Contents class but I dont have any mean of storing the instance name. I think I am not making any sense so here is some codeCode: public class TestContent extends EventDispatcher { //Class properties private var _desc:String; private static var _children:Array = new Array(); // Class Constructor public function TestContent(name:String, desc:String) { // I want to store the name assigned to this object so I can use this later this.instanceName = name; _desc = desc; TestContent._children.push(this); } public function get name():String { return this.instanceName; } public function get desc():String { return _desc; } public static function getChildren():Array { return _children; }So in another class I am using the number of objects of this class to create buttonsCode: //Some other classparentSprite:Sprite = new Sprite;var mArray:Array = new Array;mArray = TestContents.getChildren();for (i = 0; i<mArray.length; i++){var mc:MovieClip = new MovieClip(mArray[i])parentSprite.addChild(mc);}parentSprite.addEventListener(MouseEvent.CLICK, onClikc);public function onClick(e:MouseEvent):void{// here I wanna use the instance name of the TestContents object to call the desc propertytrace(e.target.desc);}I hope I am making sense hereThanks in advance
Actionscript 3.0
Posted on: Fri Jul 25, 2008 12:39 am
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Problem(I Think...) Accessing Instance Objects.
First up, my first post here, so hi to all.
Ok the problem I've got isn't really a bug, I mean the code does what I want so far, but I think I might going about it the wrong way. Simple game, a breakout clone in AS3, although this time I was messing about splitting it up into classes, but was having trouble accessing instances of those classes...
Way I got around it was to... add them to arrays... example, creating an instance of a menu...
Code:
var menuItem = new MainMenu();
menuArray.push({aButton:addChild(menuItem.createStartBtn())});
menuArray.push({aButton:addChild(menuItem.createOptionBtn())});
// some time later
menuArray[0].aButton.x = 10;
That cant be right though can it? I mean I was ok with it when I was sticking instances of blocks and player paddle etc into arrays, but now sticking the menu screen into an array?
Is there a better way of accessing them, other then adding them to an array like that?Or am I just worrying about nothing?
EDIT: Well, doesn't look like I'm going to get a reply to this thread... but no worries, I found a better solution, for anyone else who might suffer a brain fart like I did and finds this, make the external class return an object, and in the main class be sure to have an object variable handy ( var bla:Object; ), just assign the returned object to that, no need for arrays. If object variable has scope, no problems accessing it form anywhere else.
Accessing Var's Outside Of A Class Instance
Hi,
I've defined a variable in my main timeline, and I want it to be accessed from inside a function inside a class, but Flash keeps throwing errors at me, how do I do this?
boombanguk
Accessing An Instance From With A Class...how?
I'm new to actoinscript 2, and I can't work this bit out...
I've got a movieclip in the library linked to the class Blob, that movieclip contains an instance named somethingMC... how do I access it thorugh the Blob class?
Code:
class Blob extends MoveClip
{
function Blob()
{
this.somethingMC.onRollOver = function() {trace("hello");}
}
}
This fails, apparantly there's no such property "somethingMC" but it is an instance within the movieClip.
Is there something obvious I'm doing wrong?
Accessing Every Instance Of Custom Class At Once
hello
say i have a custom class that creates a box (using drawing API).
and i want to order these boxes in a grid
each box knows what they're co-ordinates are in this grid
is there a way i can tell every instance of this custom class to move from wherever they are to their respective grid co-ord with a single command ??
as in via a function in the class that says where each individual plugin goes accordingly to their co-ords....
thnx
Accessing An Instance On Stage From Within Another Class
Hi,
This really should be simple, but is proving frustratingly difficult! All I want to do is access one instance of a MovieClip on the stage (blue_mc) from within the class file of another MovieClip (red_mc).
e.g. One instance of "Blue" on the stage called "blue_mc", and one instance of "Red" on the stage called "red_mc". Both symbols are linked to class files (Blue.as and Red.as).
In Red.as, I set up a function to listen for a mouse down event. When this is triggered, I want to move the instance blue_mc. At the moment, though, I can't seem to get a reference to blue_mc.
I've looked into the new stage and root properties, but even though blue_mc is on the stage, it cannot be accessed using stage.getChildByName( "blue_mc" ) either.
Code for Red.as:
Code:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
public class Red extends MovieClip {
private function ballPressed( eventObject:Event ) {
trace( this.name + " pressed" );
trace( stage.getChildByName( 'blue_mc' ) + " not pressed" );
};
public function Red() {
trace( "Red loaded" );
this.addEventListener( MouseEvent.MOUSE_DOWN, ballPressed );
}
}
}
Can anyone point me in the right direction!?!
Thanks!!!
Chris
--
www.chrisblunt.com
Class Vs. Instance: Accessing Public Methods
I have a Segment class and instances of the segment class. Public functions called from the class itself fail, where functions called from instances work. Example:
Code:
import Scripts.Segment; // my class
import flash.geom.Point;
var p1:Point = new Point(1, 3);
var p2:Point = new Point(7, 4);
var p3:Point = new Point(4, 5);
var p4:Point = new Point(5, 1);
var mySegment1:Segment = new Segment(p1, p2); // generate two instances
var mySegment2:Segment = new Segment(p3, p4);
var p5:Point = mySegment1.intercept(mySegment1, mySegment2); // works
var p6:Point = Segment.intercept(mySegment1, mySegment2); // gives me an error
Error looks like this, by the way:
1061: Call to a possibly undefined method intercept through a reference with static type Class.
How do I access the methods without using an instance? Like the way one might use Point.distance(p1, p2)?
Accessing Class Objects Via The Name
Hello
I have a class name Contents I am creating 5 objects of this class. Is there a way to keep track of the instance names assigned to the objects. What I am doing is get all the objects of Contents class and make button out of these and when user clicks a button the I want to reterieve descrioption from Contents class but I dont have any mean of storing the instance name. I think I am not making any sense so here is some code
Code:
public class TestContent extends EventDispatcher
{
//Class properties
private var _desc:String;
private static var _children:Array = new Array();
// Class Constructor
public function TestContent(name:String, desc:String)
{
// I want to store the name assigned to this object so I can use this later
this.instanceName = name;
_desc = desc;
TestContent._children.push(this);
}
public function get name():String
{
return this.instanceName;
}
public function get desc():String
{
return _desc;
}
public static function getChildren():Array
{
return _children;
}
So in another class I am using the number of objects of this class to create buttons
Code:
//Some other class
parentSprite:Sprite = new Sprite;
var mArray:Array = new Array;
mArray = TestContents.getChildren();
for (i = 0; i<mArray.length; i++)
{
var mc:MovieClip = new MovieClip(mArray[i])
parentSprite.addChild(mc);
}
parentSprite.addEventListener(MouseEvent.CLICK, onClikc);
public function onClick(e:MouseEvent):void
{
// here I wanna use the instance name of the TestContents object to call the desc property
trace(e.target.desc);
}
I hope I am making sense here
Thanks in advance
Accessing Objects On Specific Frames From Document Class
I have a button that exists on a certain frame in my flash movie. In my document class, I try to assign an action to that button but I'm getting a null reference error when I run the movie. Here's what the trace window reports:
Code:
onConnect1 running! chatService has connected.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MethodInfo-289()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at net.flashmog::FlashMOGService/socketConnectHandler()
It got me wondering about whether it's possible to reference components or objects that exist on particular frames in a document class. Is it possible?
Here's the document class:
PHP Code:
package {
import fl.controls.TextArea;
import flash.display.MovieClip;
import flash.events.*
import flash.text.TextField;
import net.flashmog.FlashMOGService;
/**
* A simple chat application.
*/
public class ChatExample extends MovieClip {
private var lastErrorMessage:String = '';
private var chatService:FlashMOGService;
public function ChatExample() {
this.stop();
chatService = new FlashMOGService('74.94.218.51', 1234, 'chatService');
configureListeners();
chatService.connect();
}
private function configureListeners():void {
chatService.addEventListener(Event.CONNECT, onConnect1);
function onConnect1(evt:Event):void {
trace('onConnect1 running! chatService has connected.');
gotoAndStop('username');
function submitClick(evt:MouseEvent) {
if (usernameText.length > 0) {
usernameStatusText.text = "Registering username with server...";
chatService.server.registerUsername(usernameText.text);
} else {
usernameStatusText.text = "You must enter a name!";
}
}
submitButton.addEventListener(MouseEvent.CLICK, submitClick);
} // onConnect
} // configureListeners
} // class ChatExample
} // package
Accessing Objects On Specific Frames From Document Class
I have a button that exists on a certain frame in my flash movie. In my document class, I try to assign an action to that button but I'm getting a null reference error when I run the movie. Here's what the trace window reports:
Code:
onConnect1 running! chatService has connected.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MethodInfo-289()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at net.flashmog::FlashMOGService/socketConnectHandler()
It got me wondering about whether it's possible to reference components or objects that exist on particular frames in a document class. Is it possible?
Here's the document class:
PHP Code:
package { import fl.controls.TextArea; import flash.display.MovieClip; import flash.events.* import flash.text.TextField; import net.flashmog.FlashMOGService; /** * A simple chat application. */ public class ChatExample extends MovieClip { private var lastErrorMessage:String = ''; private var chatService:FlashMOGService; public function ChatExample() { this.stop(); chatService = new FlashMOGService('74.94.218.51', 1234, 'chatService'); configureListeners(); chatService.connect(); } private function configureListeners():void { chatService.addEventListener(Event.CONNECT, onConnect1); function onConnect1(evt:Event):void { trace('onConnect1 running! chatService has connected.'); gotoAndStop('username'); function submitClick(evt:MouseEvent) { if (usernameText.length > 0) { usernameStatusText.text = "Registering username with server..."; chatService.server.registerUsername(usernameText.text); } else { usernameStatusText.text = "You must enter a name!"; } } submitButton.addEventListener(MouseEvent.CLICK, submitClick); } // onConnect } // configureListeners } // class ChatExample} // package
Accessing A Dynamic Text Field In A Class Other Than The Primary Class
I have tried to read and understand some of the other threads for this issue but, I think it would be easier to understand if I show my specific issue. I left some code out to make my issue more clear.
Alpha is the primary class with access to the stage. If I write the event listener and function contained in the Bravo function into the Alpha function it works. Although, I want it to be in a different class in the same package (such as the Bravo class).
I have created a instance of a class which is a physical object on the stage (lets say it's a card). The event listener is in the instance so that each instance has a self contained listener.
The bottom line is it works in the primary class but in no others. How can I make it access the text field (so when I click on the "card" the text field shows "something"?
ActionScript Code:
package a {
public class Alpha {
public function Alpha() {
x:Bravo = new Bravo();
}
}
}
package a {
public class Bravo {
public function Bravo() {
this.addEventListener(MouseEvent:CLICK, clickEvt);
function clickEvt(event:MouseEvent) {
<MovieClip>.<MovieClip>.<DynamicTextField>.text = "something";
}
}
}
}
Tough One: Accessing Class Methodes From Other Class Files
Tough question for the experts...
In my classfile class Classes.tools.depthManager, I've got a static methode
Code:
public static function getLoopDepth():Number {
In another classfile Classes.tools.frameRateViewer, I want to access that methode
Code:
var tempDepth = Classes.tools.depthManager.getLoopDepth();
The compiler claims: "There is no class or package with the name 'Classes.tools.depthManager' found in package 'Classes.tools'."
So I tried writing import Classes.tools.* at the top of my Classes.tools.frameRateViewer.as, hoping I could just write
Code:
var tempDepth =depthManager.getLoopDepth();
But there the compiler claims: "The class being compiled, 'Classes.tools.depthManager', does not match the class that was imported, 'depthManager'."
I'm sure the Classes.tools.depthManager.as works fine: I can call the static depthManager.getLoopDepth() from a button in the fla file...
Any ideas? Thanks!
Store And Retrieve Array Of Custom Class Objects From Shared Objects.
Hi,
I am stuck up with a problem in ActionScript 2. I am using Flash MX 2004 on windows XP.
I have created 3 custom classes say Parent, Child, and GrandChild. Parent class contains in it an array of its Child objects. Similarly each Child object contains in it an array of GrandChild objects. Also I do have one global array of all the Parent objects.
I want to store this array to the shared objects on specific events(say exiting the session) and then reload them from the shared object(on next session startup). I am able to store the global array to the shared object but when I try to retrieve the same array from shared object, I could not do it. The retrieved array is not of my custom class type [Parent].
Help needed to solve this problem urgently. Does anybody have idea how to do it??
Thanks in advance.
Cheers,
Naishadh Sevalia
Accessing Document Class From Static Class?
I am building a family tree like tree in flash.
I have a package TreeManager which holds all my classes.
The document class TreeManaager.Tree controls adding new nodes to the stage.
ActionScript Code:
public function addProfile(relationship:Object):void
{
profile = new Profile();// create new profile
var align:Alignment = new Alignment();//make Alignment object
...
The profile class controls all the internal node functionality.
Question - If I have a button in my node MC (profile class) which should add a new relationship (i.e. call addProfile) how to I do this?
ActionScript Code:
public class Profile extends MovieClip {
public function Profile ():cool:
{
this.addEventListener(MouseEvent.CLICK,Tree.addProfile);
This always throws an error. I can just add the buttons events from the document class, but it would be helpful to know if you can access the document class from a packaged static class?
ActionScript Code:
// add button events
profile.mother.addEventListener(MouseEvent.CLICK,addRelationship);
profile.brother.addEventListener(MouseEvent.CLICK,addRelationship);
profile.son.addEventListener(MouseEvent.CLICK,addRelationship);
Accessing Instance Variables
Hi,
I'm trying to "duplicate" a MovieClip from library and set Variables in it. But it's not working.
Image is an Object;
Code:
var sel_image:select_box = new select_box();
sel_image.name = "sel_image"+i;
MovieClip(sel_image).vars = image;
this.holder.addChild(sel_image);
And ofc definition in the "select_box" MovieClip which is being copied.
Code:
var vars:Object = new Object;
Most likely I'm doing smth wrong.
Bigger Image of this:
I have a for each for images going through and making new instances, and putting name, loading image etc in it. I need to save the whole "image" object there so I can access on CLICK on the instance the image.id etc.
Accessing An Instance / And Getting _currentframe
I'm having difficulties accessing instances of movie clips on my _root timeline. For example, if "myMovieClip" was on the main timeline (the main timeline only has one frame) and I wanted it to run, let's say, 20 frames and then play "myMovieClip2", how would I access "myMovieClip2". These don't seem to work:
this._parent.myMovieClip2.gotoAndStop(10);
_root.myMovieClip2.gotoAndStop(10);
I'm also unable to run something like:
if (_root.myMovieClip2._currentframe == 10) {
_root.myMovieClip1.play();
}
Seems pretty simple, but it seems like I'm in the dark on how to simply access a movie clip.
And quick question number 2:
How would I access a movie clip in another scene, or better yet, start another scene, and begin playing its movie clip. These don't seem to work:
nextScene();
this.myMovieClip3.gotoAndPlay(2);
Thanks for any help.
Syntax Help With Accessing Instance Name, Dynamically...
Hey guys, n00b needs help,
I need to play a movie clip whose instance name is set into a dynamic text field. Say, if I were to have a dynamic text field named 'holder', containing the instance name 'mc1', how would I play it?
Considering incorrect syntax, this is what I'm trying to do:
Code:
_root.holder.text.gotoAndPlay(10); //which is incorrect
alternatively,
Code:
var instance_name = _root.holder.text;
_root.instance_name.gotoAndPlay(10); // which is also incorrect.
Hope I'm making sense. That ^ is what I wanna do but I'm looking for the right syntax.
HALP!
Linkage + Accessing Instance's Children
Hello.
I've created a Movie Clip (mcMain)at authoring time and created several others inside it (mc_1,...,mc_n). I've exported it for actionscript as myMC and then created the corresponding custom class.
When I try to create a new instance of myMC dynamically, I can't access the children Movie Clips from the myMC class. I can, however, access them if the instance is added at authoring time.
How can I access the children Movie Clips from the class for dynamically added instances?
Thanks in advance.
Accessing DocumentClass Instance Variables
I've got a simple question... Say you've defined an instance variable in your DocumentClass, and you want to access it from a descendant object created from a Class in the same package, what syntax would you write?
In other words, why doesn't this work...
ActionScript Code:
package somepackage {
public class DocumentClass {
public var myVar:String = "Hello world";
public function DocumentClass() {
new Tracer();
}
}
}
package somepackage {
public class Tracer {
public function Tracer() {
//??????????????????????????//
trace(DocumentClass.myVar);
//?????????????????????????//
}
}
}
Would I _have_ to pass the myVar to the Tracer object in order to access it? e.g. new Tracer(myVar);
I'm sure there's a simple answer to this, and any help on this is very much appreciated!
Cheers
Will Rice
Accessing Timeline/Instance Names
I've been searching not only the forum but the net for the perfect article to explain to me how to access the timeline and its instance names through AS3.
The only thing I can find involves frame-coding, and I'm purposely trying to learn how to create projects WITHOUT using frame-coding.
As an example, I want to make an application with a dynamic menu. I've created a button (using the up and over states) and have an additional layer inside the button that contains dynamic text. When the user adjust the menu with the content management system, a new XML is generated for each menu item. My program would then loop through and place each instance of the button on the stage and name each one using the XML's <title> tag.
I'm thinking this method is the easiest by far. When you roll over each button, the text changes colors on the up/over states. So using a dynamic text field and using the button states easily accomplishes this, not to mention I can then embed a font as well.
Do I HAVE to place this using a textField? If I do, think how much more code will have to go into that, now its not seeming so efficient.
Anyhow, here's the current code...
Code:
// Loop through XML to name and place menu buttons from left to right.
for (i=0; i < menu.button.length(); i++) {
var item:menuItem = new menuItem();
addChild(item);
item.x = xpos;
xpos += 102;
item.y = ypos;
btnTitle = menu.button[i].title.text(); //this works great
//menu_txt is the instance name of the textField in the button.
//This line of code won't work.
item.menu_txt.text = btnTitle;
// If more than 9 menu items are entered, the menu width will be
// too large and the design will break.
if(i == 8) {
i = menu.button.length();
}
}
Accessing Variables Outside Of The LoadVars Instance
I am experiencing a bit of frustration with the callback function of LoadVars. Basically, I need to access a variable private to a class in which a LoadVars instance exists. Here is a bit of my code:
ActionScript Code:
class ClassName{
private var result_lv:LoadVars;
private var callbackfunc:Function;
private var foo:String;
//other variables are defined here
function ClassName(){
result_lv = new LoadVars();
result_lv.onLoad = SICallback;
foo = "bar";
//more actions are executed here
}
public function SendInfo(callbackarg){
callbackfunc = callbackarg;
sendInfoPriv(info_arr);
/* this line references a private function
and a private var not shown here. Basically,
the sendInfo() function sends the information
using LoadVars.sendAndLoad(), with result_lv
as the "destination" instance. */
}
private function SICallback(success){
if(success){
//this is where the problem is:
var fetchedvar = this["var"];
trace(fetchedvar) //works fine; traces what it should
trace(foo) //traces "undefined", not "bar" as it should
callbackfunc(fetchedvar);
/* callbackfunc() is NOT executed, probably because
it is undefined to this onLoad instance */
}else callbackfunc(undefined);
}
//other private functions are down here
}
So, as you can see, I can't access the class's private vars from within the LoadVars.onLoad callback. Is there any way to do this?
Accessing Instance Variables From Container
I am new to Flash. I am a programmer, not a designer so this is my first foray into Actionscript.
I am creating a slide show player in Flash. It retrieves an XML file containing other .swf files that should be played, the order in which they should be played, the length of time each one should show, and the text that should be displayed.
For example:
<presentation>
<globals>
<setting name="use_transitions" value="false"/>
<setting name="use_delays" value="false"/>
</globals>
<slide src="slide5.swf" text="Slide 1" delay="10"/>
<slide src="slide3.swf" text="Slide 2" delay="10"/>
</presentation>
I have everything working except for the loaded .swf file picking up on the text to display.
I can set the Var: property on the dynamic text field to _root.dynamic_text and it will load what is in the variable dynamic_text just fine.
However, the slide3.swf and slide5.swf file have default text in them that should who if there is no text specified.
It seems that variables inside a loaded movie are not in scope.
I load the movie using:
loadMovie(slides[nIndex][0], "slideMovie");
However if my instance name on my dynamic text field is "theText" this code does not work:
this.slideMovie.theText.text = dynamic_text;
How do I dereference the dynamic text field?
Thanks for any help.
Accessing Variables From Inside The Instance
hello people !
straight to the point...
the thing is : i have defined a variable attached to a move clip via Mc.OnLoad = function *etc
so is it possible to access this variable from within the move clip ?
and if not is there another way to work this around ?
thanks in advance
Accessing Movieclips With Variable Instance Name
I'm having an issue with the drawing API. I'm using a for loop to create movieclips and assign instance names using the loop variable. I don't know how to use the methods lineTo, moveTo, etc, without prefixing an instance name.
Basically:
for(var i:uint = 0; i < 10; i++) {
_root.createEmptyMovieClip("box"+i, 0);
// draw a box
}
if I have the instance name box0, I could say box0.moveTo(0,0), etc, but since I don't know the name of the instance, how would I go about this?
("box"+i).moveTo(0,0) perhaps? haha. Is there some kind of macro like instance(string) so I can do instance("box"+i).moveTo(0,0)?
[F8] Referencing A Static Class Inside Another Class's Instance
I've got a movie loading into a framework.
This framework has 1 instance of the class main called main.
Inside this class, another class is used, but it is used directly, not as an instance. E.g.:
code:
import com.StaticClass;
class main {
private function UseStaticClass():void {
StaticClass.init();
}
}
From my movie, I can reference the main instance as _root.main. Can I reference StaticClass at all if there's no explicit instance created or it's not assigned to a public variable?
I can't modify main to include getter/setter methods, that's why I ask.
Thanks.
Static Class Variable Referencing Class Instance
I was given the task of writing a class that would send serial requests for xml data, the idea being that the requests could be added while previous requests were still in progress, but the class would queue them and wait for the reply of one request to come back before sending the next.
The way I did this was to create a class instance for each request, and the request itself would be stored in an instance variable, waiting to be sent. A static variable called queue (accessible to all instances) was then given a reference to the instance, and when this reference got to the top of the queue, queue would call the sendRequest() method on that instance.
The reason why I am using one instance per request is so that the replies can be retrieved via the instance, so keeping each request entirely discreet.
Everything works very nicely, but the problem is my IT manager looked at the code and told me that you cannot put a reference to a class instance in a class static variable... and for this reason he has informed my line manager that he has serious reservations about the code, and recommends that it is not incorporated it into the project. However, the code works very well on my local machine and on the testsite, and no-one has experienced any problems with it.
Can someone reassure me here... I can see absolutely nothing wrong with having a class static array hold references to each of the instantiated class instances. And the proof is in the pudding.. it works. Can anyone else see a problem here?
Checking To See If One Instance Of Class Hits Other Instances Of The Same Class?
Hi guys, the idea is similar to Yugop.com JAMPACK 01.
Let's say i have a bunch of balls/cells. I'm having trouble figuring out how to make it so that every other ball bounces off of every other ball.
so in short, it's really one instance being able to check all other instances of the same ball class?
any ideas guys and if you dont know what im talking about, please feel free to state that also.
Returning The Instance Name Of A Class From Within The Instance
Hi,
I'm trying to do some error reporting in my actionscript.
I have a class MyData which can be instantiated several times over in each project e.g.
var myData1:MyData = new MyData();
var myData2:MyData = new MyData();
In the error reporting I have put statements like
trace("MyData.loadData reports error.... message...");
However, I'd really like it to return the instantiated name, not the generic class name so that I can trace errors to the particular instance that is failing. Does anyone know how to do this? I've tried
trace(this.toString() + " reports error.... message...");
but I just get a name of [object object] which isn't that helpful!
Many thanks!
Accessing Dynamic Instance And Variable Names
Version: Macromedia Flash MX Professional 2004
1) I am trying to access certain instances in my flash game that change depending on certain things. Here is an example that I tried:
Works (static case):
_root.projectile1._x = currentGunX;
Doesn't Work (dynamic case):
_root.["projectile" + zLevel]._x = currentGunX;
Only to find out that the creation of the dynamic instance name with ["projectile" + zLevel] does no work in my newer version, so I need help with how to access the dynamic instance.
2) Secondly, I have a variable that I want to access in basically the same case, here it is as a static case:
Works (static case):
currentGunX = _root.controller.GUN1_X;
Doesn't Work (dynamic case):
currentGunX = _root.controller.["GUN" + controller.activeGun + "_X"];
So, all in all, I need the way to dynamically access both instances and variables. Any help is appreciated.
Accessing Library Linkage Identifier From Instance?
This has already been asked in these forums before, in several different threads (one with the same title as this), but those were a little old and I guess I'm hoping to hear a different answer. Is it possible to access the linkage identifier of a movieclip as it would appear in the library?
For example, if I have a movie clip symbol in my library called "box" and create an instance of it (either dynamically or statically) with the name "theBox", is there anyway I can get the string "box" back out of this instance? The typeof operator will just return "movieclip" and the _name property will return "theBox", and _target doesn't do it either. I'd like to be able to get just "box" somehow.
Any ideas?
Trouble Accessing Instance Names On Stage
I'm really baffled and have tried everything I can think of, but am at a loss. Help from you gurus would be sooooo much appreciated.
Flash CS3, Actionscript 3, Flash Player 9. Note, all this code is in a bunch of classes, so sorry I can't put an easy snippet up here for you to look at.
I have a movieclip (holderClip_mc) with a bunch of frames of text on one layer and some controls on another layer. Some controls are buttons (using the old SimpleButton stuff), some are movieclips. The controls are sometimes visible and sometimes not depending on the text layer's needs. I have key frames on the controls layer ,and when I don't want the controls to be there, I create a blank key frame. I have 2 problems.
1) in my class code I refer to the controls using: var myNavClip_mc:MovieClip = holderClip_mc["navClip_mc"] syntax. This works fine, but when I do the same thing for the buttons var myNavButton_btn:SimpleButton = holderClip_mc["nav_btn"] I get errors. (note: nav_btn is the instance name I gave the button during author time). When I run the debugger I see that the instance name nav_btn shows up listed in the holderClip_mc instance, but the valule for nav_btn is null. I tried setting the linkage to export for Actionscript (using base class flash.display.SimpleButton), but that didn't seem to help.
2) This is an even bigger head scratcher for me. When I navigate forward in the holderClip_mc frames, I am able to access the var myNavClip_mc:MovieClip = holderClip_mc["navClip_mc"] no problem, but when I go to a frame which doesn't have that instance on it anymore and then go back to the last frame that had it, it displays fine, but I can no longer access the instance. Again, when I run the debugger, I see going forward in the holderClip that the instance navClip_mc value show sthat it is a movie clip with all it's various properties, but when I go back, the debugger shows the value of the navClip_mc instance to be null. I tried making the last frame that it was visible on a key frame too so that when I come back to it I can access it, but again, no dice, debugger still shows it as null.
Please help!!! I'm totally stuck.
Accessing A MC Instance Name From A Text Field, And Playing It...
I have a MC with an instance name, 'JOE'.
I have a dynamic text field with an instance name, 'EMP_NAME'.
The text field is set to "" default.
Upon runtime, I assign a text value of 'JOE' into 'EMP_NAME'.
Hence, _root.EMP_NAME.text = "JOE";
Once that's done, I want the MC to check the text in 'EMP_NAME', and play if the text is 'JOE'.
As of now, I have an 'if' statement to do that check. Since I'm going to have many MCs I do not want to add more 'if' statements or 'switch' cases as that would simply be hardcoding. I want to add more MCs with unique instance names like 'JOE', 'RICK', 'PAT' etc. and should correspondingly play the MC whose instance name matches to that assigned to 'EMP_NAME' directly and not with a condition.
Ideally speaking, though the syntax is incorrect, this is what I'm trying to do:
Code:
_root.emp_name.text.gotoAndPlay(10); //which is incorrect
alternatively,
Code:
var instance_name = _root.holder.text;
_root.instance_name.gotoAndPlay(10); // which is also incorrect.
So, is there a one liner code that would directly play the corresponding movie clip once after having read its instance name from the dynamic text field, WITHOUT a conditional statement?
Me make sense?
Accessing Objects
Hi!
This is my first post here, so be nice to me )
How can i get access to objects which objectnames are saved in a string?
such as: (doesn't work)
nameOfTextfields = new Array("foobar1", "foobar2");
nameOfTextfields[0].text = "foobar";
i've tried the tellObjects() function, but isn't there an easyer way?
thx!
Accessing Objects Without Name
I put few Objects in the stage. Now I need to label them so I used the following code.
ActionScript Code:
var objectList:Array=new Array("apple","ball","cat","dog");
for(var i:uint=0;i<objectList.length;i++)
{
var obj:Object = getChildByName(objectList[i]);
var labelText:TextField=new TextFeild();
labelText.text="This is "+objectList[i];
labelText.x=obj.x;
labelText.y=obj.y;
addChild(labelText);
}
Yeppy! everything works.
Now there is a button called "clear". When it is pressed all the labels needs to be cleared.
Naturally, if I do labelText.text="", only the last label is cleared.
Any idea to clear all of them?
Delete Instance Of Class From Class' Method
So I have a class called Unit. When I use this class in a .fla file, I create it by saying:
var unit00:Unit = new Unit(...);
So then it creates a gfx representation of the screen for me. I would like to have a method like this:
PHP Code:
public function remove ():Void { unit_mc.removeMovieClip(); //deleting the gfx representation of the class in the .fla delete instance of this; //I want to delete the variable that references the instance of this class}
So how do I get this to work? I know that delete this will not work when defined inside the class. How do I target the .fla's instance name when I don't know what it will be called?
Thanks for any assistance
Class Question: How To Access Timeline Objects From Class W/o Arguments
Hey all,
I am looking into builiding an application with OO functionality. I understand most of it. Except I cannot figure out how to access something in my app from a class. For instance, lets say I have one Loader class that loads some data and stores it in a variable inside the class (or on the main timeline, doesn't matter). Now, I know I can pass a reference to the data in an argument to another class for that class to manipulate. But if I have several data sources, and other variables and such, that I need to modify in a single class function, how would I do that without having to give the function access to them through arguments? I just want to be able to say, from a class, something like _root.someObject.someFunction();
So, any help would be greatly appreciated, and sorry if that made no sense at all, I tried to explain as best I could.
Happy Holidays!
Dave
Accessing Objects In An Array
I have a card matching game I'm working on. My idea is that when two cards are turned over, they are placed in an Array. The array then checks to see if they are a match. The issue is that the card instance names will not match since both cards need to have different instance names onstage. I've tried just having the cards dump a number into the array, so then the numbers will match; but if it's not a match, I can't make the specific cards that were selected turn back over.
I could use two arrays, one for numbers and one that will hold the card MCs, but I was hoping there was a more elegant, streamlined solution.
To sum up, i guess my question is this...
When i've put an object like a movie clip instance into an array, can I use the array to access the objects' variables, functions, or anything so I can use THAT information to compare the cards other than their instance names?
Accessing Objects In Other Functions.
I'm working on a flash video player and I'm trying to figure out how to access something inside the constructor that I know is set but it keeps telling me its not.
Here is the code
ActionScript Code:
package player {
import flash.display.Sprite;
import flash.media.Video;
import flash.net.NetStream;
import flash.net.NetConnection;
import flash.utils.Timer;
public class InfernoPlayer extends Sprite {
// Declare variables
var vWidth:Number = 720;
var vHeight:Number = 480;
var duration:Number;
var ratio:Number;
// Set up the stream and video object
public function InfernoPlayer() {
// Create the video object
var video:Video = new Video(vWidth, vHeight);
addChild(video);
// Create a new NetConnection and connect / open a NetStream channel
var netCon:NetConnection = new NetConnection();
netCon.connect(null);
var netStream:NetStream = new NetStream(netCon);
// Set up the meta data handler and resize video if it is to small/large
var meta:Object = new Object();
meta.onMetaData = metaData;
netStream.client = meta;
// Attach video to the NetStream and start then pause playback
video.attachNetStream(netStream);
netStream.play("videoURL");
}
private function metaData(meta:Object):void {
var duration = meta.duration;
var ratio = meta.height / 480;
video.width = meta.width / ratio;
video.height = meta.height / ratio;
}
}
}
now in the metadata function its giving me the error, "Access of undefined property video"
Now, am I just completely not understanding how classes work or is this a common problem?
Accessing Objects Inside Another Swf
I am trying to keep from building one large swf in order to help a broswer window to launch more readily (28k modem audience). Can I have a button in one swf run a movie clip inside another swf in this same browser window?
Thanks
AS3 Accessing External SWF Objects
Hello
I do understand that in Flash 8 (AS2) you can create and empty clip, then load SWF file and access objects inside it through this movieclip. For example if I have an instance of somethig called "inst" and I compile SWF, then after I load it in another project I can do MovieClipName.inst._x = 50;
Now in Flash 9 (AS3) I cant do that, since I have to use the loader, and if I try to do LoaderName.inst._x = 50 - that would not work. So how should I have to do this now?
In few words I have a project called MainProject.fla there I load up a movie with this:
var _ldr:Loader = new Loader;
var _req:URLRequest = new URLRequest("test.swf");
_ldr.load(_req);
Now in test.swf I have a bitmap with instance called "MyBitmap" . How can I change position of that bitmap in that SWF file after I load it?
Help With Accessing Dynamic Objects
Hi all
Ok its my third day on the AS3 learning curve, go easy on me:)
Hit a problem and hope someone can help..
I have created a several child objects (MovieClips) they inturn have their
own birthed objects inside them
MC_Holder < MC_Holder_Preload < MC_Holder_Preload_TextField
MC_Holder < MC_Holder_Sprite < MC_Holder_Image
So MC_Holder has two child MC's etc etc
This all works fine!
The problem im having is that when "MC_Holder_Image" runs, the
ProgressEvent.PROGRESS listener needs to update the
"MC_Holder_Preload_TextField", just wondering how i get the information into
this dynamic object...
There are 32 of these at present they all have been given names from a loop
("Name "+i)...
So the objects i will need to update will be "MC_Holder_Preload_TextField_0"
through "MC_Holder_Preload_TextField_31"
private function progressHandler (event:ProgressEvent):void
{
event.target--->NEED HELP HERE<--- = event.bytesLoaded;
}
Everyrthing works fine, the images are loading from an XML schema etc etc...
Sorry if that sounds crazy, late here 04:44 infact...lol, coffee for the
correct answer!
Thanks
Rick
Code For The Class :
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.*;
import flash.net.*;
import flash.display.*;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.Font;
import flash.text.*;
import xmllist;
public class imagemc extends MovieClip
{
public var ldr:Loader = new Loader();
public var holder_Preloader:MovieClip = new MovieClip();
public function imagemc (xmlArray,URLimages):void
{
trace ("CLASS CONSTRUCTOR : IMAGEMC");
for (var i:int=0; i<xmlArray.length; i++)
{
buildSlideContent (xmlArray,URLimages,i);
}
}
public function buildSlideContent (xmlArray,URLimages,i):void
{
// CREATE MAIN CLIP
var holder:MovieClip = new MovieClip();
holder.graphics.lineStyle (1, 0xFF0000, 1);
holder.graphics.moveTo (0, 0);
holder.graphics.lineTo (760, 0);
holder.graphics.moveTo (760, 0);
holder.graphics.lineTo (760, 390);
holder.graphics.moveTo (760, 390);
holder.graphics.lineTo (0, 390);
holder.graphics.moveTo (0, 390);
holder.graphics.lineTo (0, 0);
holder.name = "MC_Holder_"+i;
holder.x = 0;
addChild (holder);
// IMPORT TEXT
var Font_Levenim:Font=new Font1();
var Font_Levenim_Format:TextFormat = new TextFormat();
Font_Levenim_Format.font=Font_Levenim.fontName;
// CREATE TEXT FIELD //
var holder_Preloader_Text:TextField = new TextField();
holder_Preloader_Text.defaultTextFormat = Font_Levenim_Format;
holder_Preloader_Text.embedFonts = true;
holder_Preloader_Text.name = "MC_PRELOADER_TEXT_1_"+i;
holder_Preloader_Text.x = 0;
holder_Preloader_Text.y = 10*i;
holder_Preloader_Text.width = 350;
holder_Preloader_Text.height = 20;
holder_Preloader_Text.border = false;
holder_Preloader_Text.background = false;
holder_Preloader_Text.text = "HELLO";
holder_Preloader_Text.textColor = 0xFF0000;
holder_Preloader_Text.multiline = false;
holder_Preloader_Text.wordWrap = false;
holder_Preloader_Text.selectable = false;
// CREATE PRELOADER CLIP //
var holder_Preloader:MovieClip = new MovieClip();
holder_Preloader.graphics.lineStyle (1, 0xFF6600, 1);
holder_Preloader.graphics.moveTo (0, 0);
holder_Preloader.graphics.lineTo (760, 0);
holder_Preloader.graphics.moveTo (760, 0);
holder_Preloader.graphics.lineTo (760, 390);
holder_Preloader.graphics.moveTo (760, 390);
holder_Preloader.graphics.lineTo (0, 390);
holder_Preloader.graphics.moveTo (0, 390);
holder_Preloader.graphics.lineTo (0, 0);
holder_Preloader.name = "MC_PRELOADER_"+i;
holder_Preloader.x = 0;
holder.addChild (holder_Preloader);
holder_Preloader.addChild (holder_Preloader_Text);
// CREATE IMAGE HOLDER SPRITE
var holder_Sprite:Sprite = new Sprite();
holder_Sprite.graphics.lineStyle (1, 0xFF6600, 1);
holder_Sprite.graphics.moveTo (0, 0);
holder_Sprite.graphics.lineTo (760, 0);
holder_Sprite.graphics.moveTo (760, 0);
holder_Sprite.graphics.lineTo (760, 390);
holder_Sprite.graphics.moveTo (760, 390);
holder_Sprite.graphics.lineTo (0, 390);
holder_Sprite.graphics.moveTo (0, 390);
holder_Sprite.graphics.lineTo (0, 0);
holder_Sprite.name = "SP_Holder_"+i;
holder_Sprite.x = 80;
holder.addChild (holder_Sprite);
// CREATE IMAGE
var ldr:Loader = new Loader();
ldr.name = "IMG_"+i;
var url:String = URLimages+xmlArray;
var urlReq:URLRequest = new URLRequest(url);
ldr.load (urlReq);
ldr.x = 0;
configureListeners (ldr.contentLoaderInfo);
holder_Sprite.addChild (ldr);
}
private function configureListeners (dispatcher:IEventDispatcher):void
{
dispatcher.addEventListener (Event.COMPLETE, completeHandler);
dispatcher.addEventListener (HTTPStatusEvent.HTTP_STATUS,
httpStatusHandler);
dispatcher.addEventListener (Event.INIT, initHandler);
dispatcher.addEventListener (IOErrorEvent.IO_ERROR, ioErrorHandler);
dispatcher.addEventListener (Event.OPEN, openHandler);
dispatcher.addEventListener (Event.UNLOAD, unLoadHandler);
dispatcher.addEventListener (ProgressEvent.PROGRESS, progressHandler);
}
private function completeHandler (event:Event):void
{
trace ("HANDLER : COMPLETED > " + event +
event.currentTarget.loader.name);
}
private function openHandler (event:Event):void
{
trace ("HANDLER : OPEN > " + event + ldr);
}
private function progressHandler (event:ProgressEvent):void
{
---------------------------------------------------------------------------------------------------------->
HELP event.target.="HOOOOOOOOOOOOO"; <-----
trace ("HANDLER : PROGRESS LOADED > " + event.bytesLoaded + " total: " +
event.bytesTotal);
}
private function securityErrorHandler (event:SecurityErrorEvent):void
{
trace ("HANDLER : SECURITY > " + event);
}
private function httpStatusHandler (event:HTTPStatusEvent):void
{
trace ("HANDLER : HTTP STATUS > " + event);
}
private function ioErrorHandler (event:IOErrorEvent):void
{
trace ("HANDLER : I O ERROR > " + event);
}
private function unLoadHandler (event:Event):void
{
trace ("HANDLER : UNLOADED > " + event);
}
private function initHandler (event:Event):void
{
trace ("HANDLER : INIT > " + event);
}
}
}
Accessing The Tab Order Of Objects
Hello,
I am having difficulty determining the identity of the next object in the tabbing order. I set the tabIndex of a group of text fields as they are attached and upon running the app the tab key works as expected. However, another requirement is that upon a condition (say length of field reached while typing) I want to actionscript to move the focus to the next text field in the tabbing order. The problem is I don't know what field that is.
getFocus() will return me a tabIndex of the field I am on. But setFocus() wants an object name. focusManager has a nextTabIndex property but there again, just a number. I could build my own array of objects as I set the tabIndex, but that seems a little clunky and operates independently of Flashes handling of it.
I understand this functionality was meant for use with the tab key, but it sure would be nice to query against wherever Flash has stored its reference to objects in tab order. Is that possible? Or is there another way to approach moving the focus the next field without requiring a tab keystroke?
Thanks for any help you may provide.
Accessing Array Within XML Objects
Here's my code:
Code:
function loadProjects(loaded){
if(loaded){
projects = this.firstChild.childNodes;
projectName = new Array();
projectImage = new Array();
projectDesc = new Array();
projectShtDesc = new Array();
projectLink = new Array();
projectNext = new Array();
for(i = 0;i < projects.length;i++){
projectName.push(projects[i].attributes.name);
}
trace(projectName);
trace(projectName.length);
}
else {
trace("PROJECTS NOT LOADED");
}
}
projectData = new XML();
projectData.ignoreWhite = true;
projectData.onLoad = loadProjects;
projectData.load("projectData.xml");
var numProjects = projectName.length;
trace(projectName);
trace(numProjects);
the traces within the function return correct results, however when trace values of the arrays within the function and created by the xml are attempted results are returned 'undefined'.
Why can I not access arrays made in this way from outside of the function?
thanks!
Accessing Objects Within MovieClips
I'd like to use instance names to access movie clips that are inside other movie clips, which may be inside other movie clips, etc. Everything works fine until things start moving, and then instance names become weird...
Sometimes, I can access the instance name, but tracing the position reveals that it isn't moving (even though I can see it moving on the screen!)
Sometimes, I can't even access the instance name, and even getChildByName returns null.
It's been driving me crazy for days now... Could anyone shed some light on this issue, what's going on???
Thanks a lot!
Emil
Accessing Objects In DisplayList
Hi,
I have problem with accessing objects in AS3.0.
Suppose I write this code on MainTimeLine:
Code:
var sprite1:Sprite = new Sprite();
var sprite1Child:Sprite = new Sprite();
sprite1.addChild(sprite1Child);
addChild(sprite1);
//custom class
var myMC:myMovieClip = new myMovieClip();
Now from myMC I want to reference sprite1Child object.
How?
To access sprite1 I use this code inside myMC:
Code:
this.parent.getChildAt(0)
That works, but I can’t reference sprite1Child which is inside sprite1.
Thanks,
Accessing Objects On Stage
Hello all,
Could someone explain me the concept of objects at the stage? How I would access them.
For example: I've made 3 classes, in one of them I made an container that contains a Circle. In another class I want to access them. So I know the structure of the stage is now as follow:
stage
_ container
____ circle
First I thought about giving the container a name so I could access it with getChildByName(). Only when I try stage.getChildByName() I get the error that I cannot access a property or method of a null object reference.
Thanks in advance
Accessing Objects In Other Functions
I'm having difficulty controlling objects created in one function, by another function. I'm adding the children to the stage, stage.addChild("lrg" +i), and trying to reference the children by stage["lrg"+id]. I think I'm just doing something wrong with the syntax. Any ideas?
Here's the error I'm getting:
Code:
ReferenceError: Error #1069: Property lrg8 not found on flash.display.Stage and there is no default value.
at playertest2_fla::MainTimeline/showPicture()
And here's the relevant code:
Code:
function loadXML(event:Event):void {
currentPlaying = 0;
xml = XML(event.target.data);
xmlList = xml.children();
for (var i:int=0; i < xmlList.length(); i++) {
imageLoader = new Loader();
imageLoader.load(new URLRequest(searchAndReplace(xmlList[i].attribute("tn"), "/tn/", "/tn2/")));
imageLoaderBig = new Loader();
imageLoaderBig.load(new URLRequest(xmlList[i].attribute("tn")));
imageLoaderBig.y = 268;
imageLoaderBig.x = i * 50 - 18;
imageLoaderBig.alpha = 0;
imageLoaderBig.name = "lrg" + i;
stage.addChild(imageLoaderBig);
this["myHolder" + i] = new MovieClip();
stage.addChild(this["myHolder" + i]);
this["myHolder" + i].y = 335;
this["myHolder" + i].x = i * 50 + 10;
this["myHolder" + i].addChild(imageLoader);
imageLoader.name = "id" + i;
this["myHolder" + i].addEventListener(MouseEvent.MOUSE_OVER, showPicture);
this["myHolder" + i].addEventListener(MouseEvent.CLICK, showVideo);
}
}
function showPicture(event:MouseEvent):void {
var hovered = searchAndReplace(event.target.name, "id", "");
trace(hovered);
trace(stage["lrg"+id]);
}
Accessing Data In Objects
I posted on the XML boards but later realized that this particular question is more of a Actionscript question.
I just used Branden Hall's ©Deserializer to convert WDDX into a flash object. The object mimics the structure of the wddx (xml nodes). How can I properly access the data in an Object (with nodes of data)?
|