ActionScript 3.0 :: Dynamic Reference To MC's On Stage?
Sep 30, 2010
I have 9 MovieClips on stage (p1, p2, p3...), different colors and sizes. I have one AS3 class -Snake- that as an instance is supposed to duplicate one of these MC's as a Shape. The reference to the specific MC is supposed to be on the constructor method. These instances are supposed to be triggered from one global Enter.FRAME event.
My question: How can I refer a distinct MC from within a class? I ask this because this MC will be dynamic and its properties ever-changing (position and color). I know this can be solved by adding distinct Enter.FRAME listeners per instance, but I'd rather avoid bad practices.
[Code].....
View 1 Replies
Similar Posts:
Sep 30, 2010
I have 9 MovieClips on stage (p1, p2, p3...), different colors and sizes. I have one AS3 class "Snake" that as an instance is supposed to duplicate one of these MC's as a Shape. The reference to the specific MC is supposed to be on the constructor method. These instances are supposed to be triggered from one global Enter.FRAME event. How can I refer a distinct MC from within a class? I ask this because this MC will be dynamic and its properties ever-changing (position and color). I know this can be solved by adding distinct Enter.FRAME listeners per instance, but I'd rather avoid bad practices.
ActionScript Code:
public function Snake(id:MovieClip) {
body = new Array();
head=new Point(id.x, id.y);
size = id.width;
color = getColor(); // need to have a class variable that refers to the index
[Code] .....
View 1 Replies
Jun 9, 2010
I am currently working with a contractor company that is hosting a flex based website. They are putting the swf files that I have developed into their flex site.The issue that I am having is that within my swf file I need to reference the stage.I do this by "MovieClip(parent).stage"... I do not use the keyword "root", I just reference my swf's root through however many "parent"s i need. It works fine when I publish on my own, outside of their flex site. When it is used in the flex site, they are getting an error that they cannot reference the stage/ stage is null. It is vital that I am able to reference the stage of my swf.
View 2 Replies
May 1, 2009
I have a dynamic group of movieclips... these fade in/out on rollOver/rollOut. During the rollOver they reference an index in the legendArray. In the legendArray each index has 5 digits (0 = off, 1=on). Over each "bg" mc are a series of 5 dynamics mc's ("dt" mc (see eg.jpg)), which are to change tint via tween, depending on the legendArray index. I have been able to associate the btn("bg" mc) with the proper legendArray index, but for some reason I'm having difficulty associating the legendArray index to the "dt" mc. As it stands, I keep getting error 1069.
[Code]...
View 1 Replies
Nov 17, 2010
I am currently working with a contractor company that is hosting a flex based website. They are putting the swf files that I have developed into their flex site. The issue that I am having is that within my swf file I need to reference the stage. I do this by "MovieClip(parent).stage"... I do not use the keyword "root", I just reference my swf's root through however many "parent"s i need. It works fine when I publish on my own, outside of their flex site. When it is used in the flex site, they are getting an error that they cannot reference the stage/ stage is null. It is vital that I am able to reference the stage of my swf.
View 2 Replies
Sep 22, 2009
In my document class, I am instantiating a class like this:
cues = new CuePoints();
cues.addEventListener(CuePoints.CUE_POINTS_CLASS_ADDED, setCuePoints);
addChild(cues);
[Code]....
If I try to reference a MC that sits on the stage called videoPlayer_main like so: stage.videoPlayer_main I get the following error: 1119: Access of possibly undefined property videoPlayer_main through a reference with static type flash.display:Stage.
View 1 Replies
Sep 22, 2009
In my document class, I am instantiating a class like this:
cues = new CuePoints();
cues.addEventListener(CuePoints.CUE_POINTS_CLASS_ADDED, setCuePoints);
addChild(cues);
[code].....
View 3 Replies
May 25, 2010
I'm trying to get a small popup (a volume bar) to work from within a class.I made a piece of actionscript code that creates an empty movieClip and draws the bar into it and made it onto a class. The only thing I now have to do to add the bar to a programm, is create an instance of that class. Nothing needs to be added to the stage.The problem I encounter is that I need the bar to stay on top. New movieclips always get higher depths (using getNextHighestDepth()), so that's a problem.Calling swapDepths() for every new movieclip is far too complex and afaik there is no such thing as "bring to front" in actionscript, it only exists at design time, not at runtime.
So I though I'd use 2 layers/movieclips in the timeline, one for the volume bar and one for the rest, and add an empty movieclip to both.This way I know that all children I add to one movieclip will alway lay below anything I add to the second movieclip. (or is there an easier way to accomplish what I need? Levels maybe? I've never looked into levels, I only know they exist when loading a clip)This means I need to add a some extra stuff to the stage at design time, but if this fixes the issue.. ah well.But how can I access that movieclip from within a class? The reference "_root.volumeBarPlaceholder" works from within the main actionscript, but not from within a class because I get the compiler error "There is no property with the name '_root.volumeBarPlaceholder'";
View 2 Replies
Sep 13, 2010
How do I reference the stage from a class? I need to add eventlisteners to the stage for mouse movement. I also need to add custom cursors. I always get an error when I try to reference stage. anything. Or event if I do this:
[Code]...
View 20 Replies
Jun 16, 2011
I have some object, which extends movie clip:public class MyClass extends MovieClip Now, I want to put two of this in the stage:[code]That would put one, but the other I want it to be exactly the same as the first, so I just need to add a "reference" of obj to the stage, along with obj itself.In the end, I want two objects of type MyClass doing the same thing in the stage. If I try to simply do:[code]only obj2 will appear in the stage.How could I achieve that with references? (in order to save memory and CPU time (it is really important))
View 6 Replies
Oct 9, 2010
How can i reference objects on stage so i can push them into an array using a loop?[code]...
View 2 Replies
Aug 9, 2011
I'm playing around with some classes from my Learning AS 3.0 book in an attempt to understand them. I have a main (document) class, and a class called NavigationBarXML.
Because the buttons for the nav bar are all set up in the subclass NavigationBarXML, I would like to position the nav bar relative to the stage (think btn1.x = stage.stagewidth - 50) from within this class. I understand that you cannot deal directly with the stage from a subclass and that you must add it to the display list before you can reference the stage from within this class.
How would I set up the main class so that I can reference the stage from my subclass so that on browser resize, my nav bar is positioned relative to the stage?
View 9 Replies
Feb 17, 2009
I have a static utility class that must have a reference to the stage, and I'm not sure what is the best option for me to get the stage inside my class...
I've thought of these options:Pass in as a parameter of the function Have a static variable I can set to the stage I don't like either of these because they are ugly.
What methods can you suggest for me to get a reference to the stage in my static class?
View 8 Replies
Jul 4, 2009
from my documentclass i got a isntance of the my view class in there i got a instance of navigation class extends Sprite I got a utilz.as file with all static public functions like this one
alignToCenter(obj:DisplayObject):vid
{
obj.x = obj.stage.stageWidth/2;
}
Utilz.alignToCenter(instance of navigation class)
I get a error stage is null reference..
View 7 Replies
Nov 4, 2009
Ive got two classes and my stage. I'm trying to use an array to keep control of my enemy class's number for collision purposes and I managed to get the enemies to populate the array.
View 3 Replies
Nov 5, 2009
In simple example, I have a class called RedSquare that extends a Sprite. I need to have it in a central position of the stage. I do not know if importing definition of Stage class to RedSquare changes anything, but in the constructor of the class i could write [code]...
View 2 Replies
Nov 21, 2010
1) I have a movieclip instance on stage (simple graphical element that represents platforms for a hero to run and jump along). I have placed it on the stage with an external class engine.as and in this class it is called myPlatform and is an object of Platforms.as. The movieClip is called platforms and from a trace(myPlatform.name) the instance name is instance3.
2) I am attempting to access the properties of myPlatform in an Enterframe event loop in my character control and collision class (called hero.as)Basically here is the bit of code I am trying implement within Hero.as :
if (myPlatform.hitTestPoint(x,y,true)) { // if a platform is hit
trace("hitME");
y--;
tGravity = 0; // reset
break;
}
Here's the error that I get:
1120: Access of undefined property myPlatform
This all worked when I was writing actionscipt within the FLA file, on the timeline frame 1.I simply don't know how to access myPlatform from within the external Hero.as class! Do I need to create a variable?
View 1 Replies
Aug 22, 2008
I have an array of MovieClips, when I try and use .removeMovieClip on one of the array items it removes reference to the MovieClip Object but it is still visible on the stage. When I address the MovieClip directly and use removeMovieClip on that it removes references and deletes from the stage.
i.e.
Scenario 1:
myArray = new Array();
myArray.push(myMovieClip);
myArray[0].removeMovieClip();
trace(myArray[0]);
trace(myMovieClip);
Traces out undefined, undefined but the movieClip is still visible on stage (and can still interact with).
Scenario2:
myArray = new Array();
myArray.push(myMovieClip);
myMovieClip.removeMovieClip();
trace(myArray[0]);
trace(myMovieClip);
Trace out undefined, undefined and the movieClip is removed from stage
View 3 Replies
Feb 6, 2009
I have created a custom class that extends the movie clip on frame 1 of the main timeline I create it var mainBox2:mainBox = new mainBox(); addChild(mainBox2); Now as I understand it you have to cast the parent as a MC so in the constructor of my external class I try this var myStage:MovieClip = MovieClip(this.parent); trace (myStage); I get null. What am I doing wrong?
View 1 Replies
Sep 28, 2010
I have 2 input textfields on the stage and 1 dynamic textfield.
-input1 is for quantity
-input2 is for page count
When a user enters a number into the page count it makes a calculation and places the outcome into the dynamic textfield. This textfield is for the individual price.All of this so far works. What I want to do now is create another dynamic textfield for the total. So the individual price is multiplied by the quantity and this result is put in the new dynamic text field. I have the code for that working but here is where it gets tricky (for me anyway).The total price is to start off invisible. When I roll over the individual price the total price is to appear (For a test lets just say when I roll over an area the total price appears).To stop cursor flickering this should be done inside a movieclip. So... I have create a movieclip and placed a dynamic textfield inside it. They all have instance names BUT how do I reference it in script?I need to tell the resulting calculation to be placed inside the textfield which is inside the movieclip. If it isn't inside a movie clip I can do it. But how to I reference it when inside one?
View 1 Replies
Jun 9, 2009
Using AS2. I have a variable defined:
activenav = "services";
I then want to reference the variable in a MC string. I've tried many variations of this:
_root.my[activenav]Clip.gotoAndPlay("Out");
Essentially, I want Flash to see this as:
_root.myservicesClip.gotoAndPlay("Out");
Getting syntax error.
View 2 Replies
Dec 9, 2009
Been trying to make the transition from AS 2 to 3 but not without it's speed bumps. My first major hurdle has been trying to dynamically reference a class by only knowing it's name. I came across the code of import flash.utils.getDefinitionByName; but that's not working for some reason. It keeps giving me the error:
Quote:
ReferenceError: Error #1065: Variable characterType5 is not defined.
My code in getting this is:
PHP Code:
import flash.utils.getDefinitionByName;
var className:String = "characterType" + 5;
var tempClass:Class = getDefinitionByName(className) as Class;
var char = new tempClass();
View 2 Replies
May 9, 2009
how does one reference a MovieClip instance dynamically in AS 3.0? Example, I create a new instance of a "marker" MovieClip class that inherently has within it a series of embedded MovieClips labeled: "m1", "m2", "m3" etc ... and I want to be able to dynamically reference those embedded MCs.I used to do this all the time in AS 2.0, and can't recall how to do it in AS 3.0.I know it is something like this:
number = 1;
marker = new StaticMarker();
var thisMarker = this.marker.m[number];[code].........
View 3 Replies
Aug 3, 2009
I am having trouble dynamically changing the reference to root in my movies. Here's what I'm trying to do: I have a main movie(_level0.mainMovie) that I am loading external .swfs into. However, I want to be able to test the child movie clips without having to load them into the mainMovie(for testing purposes). In such a case, the child clip would be at _level0 or _root. I would like to add some code to the child clips to test whether they are the _level0 clip, if not, then I want to change their reference to _root. Here's what I've come up with, which doesn't seem to work:
ActionScript Code:
function testLevel(){
//This code goes into each child clip to see if it has been loaded into another clip
[code]...
View 0 Replies
May 26, 2010
I'm having some problems on how to reference dynamically placed buttons. I am building a shopping cart and for every item in the cart a movieclip is duplicated and next to this movieclip I duplicate a few buttons (to delete and add an item)This is the code:
Code:
var id=0; //this value normally comes from the database
var amount = 10;//this value normally comes from the database
[code].....
View 9 Replies
Jan 23, 2009
getChildByName("name") works great if my object has been added to the stage or some MC. But what can I do if I have an object created dynamically that I want to reference later in the code but haven't added to the stage? Here's an example:
for (var a = 0; a < 10; a++) {
var testObject = addChild(new BlankMC());
testObject.name = "myTest_" + a;
}
[Code]....
This returns my BlankMC instance, but ONLY because it was added to the stage. If I don't use "addChild", then I get "null" because my instance is not a child of the stage (or anything else as far as I know). Is getChildByName the ONLY function for referencing a dynamic element?
View 2 Replies
Sep 3, 2009
I have a number of identical movie clips that are generated in responce to an XML file. I'm trying to reference a specific one of these movieclips after a sound file stops playing How do I call up that specific movieclip? How can dynamically created objects be referenced through the actionscript?
PHP Code:
for(var i = 0; i < 3; i++){varnew test() addChild(a); 150);
[code].....
View 5 Replies
Dec 8, 2011
I hope the title makes sense otherwise:Is it possible to have SOUND or @JOKES to be variable?As in replace it with a String for example and have it filled in via code.champSoundJokeBtns = mySoundsXML.SOUND.@JOKES;
View 2 Replies
Nov 17, 2011
I'm unable to load forces.swf (assume I can't edit it, as I don't have the source code) through an external swf, due to Stage reference in the base class how would I go about loading it (and any other possible SWF) without errors being thrown?
Here is a link to the problem I am trying to fix:[URL]..
View 1 Replies
Nov 22, 2011
I am currently having problems referencing a MovieClip child which I add to the Stage from the Document Class. Basically when the MovieClip child is added to the Stage from the Document Class, I want a certain MovieClip already on the Stage to reference it once it is on the Stage.
Also, if it is possible, I don't want the MovieClip referencing the child being added to the Stage to have parameters linking it with the Document Class, because I plan on nesting this MovieClip within another MovieClip later on in the future.
Here is the code for the MovieClip class which is referencing the child once it is added to the Stage:
package com.gameEngine.assetHolders
{
import com.gameEngine.documentClass.*;
import com.gameEngine.assetHolders.*;
[Code].....
View 2 Replies