ActionScript 3.0 :: Passing A Display List Name Out Of A Class?
Feb 26, 2010
I am trying to pass the display list name that is inside the trace statement back out of this class. Essentially I what I want, is that when someone clicks on the "Button_mc" movie clip, I want to pass the instance name back to a different class I've been trying to figure this out all day with no luck and I was wondering if someone would be willing to give me a hint.
package { import flash.display.*; import flash.events.*;
public class button_mc extends MovieClip public var
current_button_name:String;
var t:TextField = new TextField(); t.text = "hello in main"; addChild(t);
However, when I create an instance of a class, and I have that same code in the constructor of that class, the text doesn't show up. I am creating the text field variable at the class level, not the contstructor level, so I think the variable should still hang around.
Do I have to get an instance of the stage, or something?
What i'm trying to do is create an errorAlert class. The role of this class is to as you might expect display an alert:) So the current class is set up in such a way.
1. pass in an errorcode returned from the server into the constructor.
2. This runs through a switch and sets a msg variable to the right textual prompt based on the code. At this stage it also sets an alert type, so as an example it could be a severe alert where the user has no option other than ot refresh the browser. Or it is a softer alert where the user is able to press a close button and proceed.
Because all of the type handling and everything is held within the class. I want to avoid adding the instance to the display list within the main document class. Ideally just letting the class add itself to the stage AND IF it is a softer alert, it can show the close button, add an event listener, and, then remove itself.
I have very simple code for a class: package {import flash.text.TextField; import flash.display.Sprite; public class Greeter extends Sprite { public function Greeter(){var txtHello:TextField = new TextField(); txtHello.text = "Hello World"; trace("hi"); addChild(txtHello);}}}
The above file is saved as Greeter.as in say folder C: est I then create a Fla file named test_display.fla (saved in C: est) and its contents are: import Greeter;var tt:Greeter = new Greeter(); Now the Output window shows hi due to the trace statement but the addChild method should show World in the Flash movie but it does not. The only way to get Hello World to the Flash Movie is to change the test_display.fla to:
import Greeter;var tt:Greeter = new Greeter(); addChild(tt);
In other words I have to use the addChild method twice ( once in Greeter.as and once in test_display.fla ) to get Hello World to display in the Flash movie. Does anyone know why this is so?
Now how is it that I can add the variable SPRITE which is a Sprite in the OBJECT_square class to the display list of MAIN class? I've tried addChild(SPRITE) and super.addChild(SPRITE). If everything works I should see a red square somewhere on the screen but right now its all blank, except for the text drawn in the MAIN class.
Basically I want it so i can just make a new OBJECT_square and it will draw itself without any more instructions from the MAIN class.
I have a list containing display objects from throughout the application (insertion order). I want to process the list either top-down (parent, child) or bottom up (child, parent). The only requirement is that either a parent is processed before any child or vice versa a child before its parent. What is a good approach? This question is not about sorting a list. It's about retrieving the depth of a particular display object.
Example Display list: A (root) B1 C1 C2 D1 B2 ......
My list: list = [E1, F4, A, B2, B1, C3, ..., N9, N8]
Bottom-up: N9, N8, F4, E1, C3, B2, B1, A
Top-down: A, B2, B1, C3, E1, F4, N9, N8 Does not matter if N9 before N8 or N8 before N9. Important is that any N is before M (first run) or any M before its children N* (second run).
How do I identify all the display objects in the display list in ActionScript, bellow the one that I have clicked? All the other objects are shadowed by the first one. What if other objects have visible parameter as hidden?
This is my first time working with a class attached to a movieclip that is nested inside a class attached to a movie clip.I've tested all the properties and methods of PTListItem.as and they work properly but when I try to call them on the list item through PTListTop.as it returns undefined.The end goal is to dynamically load a checklist via a txt file.
It's my understanding that a display object cannot be in the display list more that once.So if I add something to the stage shouldn't a second addition of the same object replace the first? for instance:
[code]...
there should now only be one "myDisplayObject" on the stage.
i have a movie clip which is exported for ActionScript , i want to get a variable from the document class into the movie clip class i tried this but there was an error !!
ActionScript Code: var main:Main=new Main(); main.txtScore.text="hello";
I created a movieclip with a star. Then, I creates a document class and I named it as Main.as.
In that document class I wrote: package { import flash.display.*; public class Main extends MovieClip
[Code]....
I´m not posting here all the code, but you can easily see that I´m using x_origin and y_origin variables to keep the original position of the movie clip. I will use them to move the star back to the original position.
The problem is that instead of being 20 and 30 respectively, tracing them I see that they are both ZERO. So when I drop the star, instead of going to x=20,y=30 it moves back to x=0 and y=0. I´ve to get the star position relative to stage, but I can´t find anyway!
I'm trying to create a class which will create a tween for several different instances of an object. I am creating the instances in the Document Class. The trick is, I would like to specify how long each tween will take.
As you can see, I have a variable "myTime" which syncs the timer and the tween. This causes to tween to repeat and the clouds to continually scroll across the stage. How can I determine the var myTime at the time I create each instance of the Movie Clip mcCloud?
I am trying to create a generic List, where I can pass the layout & item renderer as parameters.Since it is not possible to pass parameters to a MXML component's Constructor, I figured I should create my List in Actionscript.
[Code]...
I would prefer to have the List in MXML (because It will be easier using states later), but If I am forced to use pure Actionscript so I can instantiate it and pass in parameters, any help would go a long way.
I've got a document class (EgoGame.as) and another class (Ball.as) which has been duplicated to deal with several different video pieces. Inside the document class is a list of 'if' statements which decide which video should be played. At the moment I'm doing it the old fashioned way whereby if the condition is true....it tells the relevant Ball class to gotoAndPlay a certain frame within the linked movieclip...
I'm currently working on a flash combobox and text field passing data to php to display the input from flash. It require using query string method. I'm stuck on the query string code. My as3 has nothing wrong, I just don't know whats going on the php is not catching my data for display.
The php I'm targeting looks like this: <?php $current_page_num = 1; require_once 'dir/php.php'; $use_GET = $_GET[ 'use' ]; if ( $use_GET ) { $timestamp = $use_GET; [Code] .....
I'm having alot of trouble tracking down the name of an object on the display list so i can removeChild Is there a way to trace every object on the display list so i can get its name and remove it? my stage is changing dynmically and i can't jut trace each object through a whole whack of code.
I have a list box in my flash file that I would like to display a string from an xml file that has been run though html entities in php. So for instance I need the string.
Code: Hey "Leonardo£$£$()*%£% '"' [1999] to display as Code: Hey "Leonardo;$;$()*%$% '"' [1999]
I can get this to happen in my dynamic text boxes by using .htmlText to display but I have no idea how I would do this in the list box?
All it returns is 0 and [object MainTimeline]. Is there something wrong with Flash, or did I do my coding wrong? The objects I put on the stage should be on the Display List, right?
How do I removeChild only if it's in the Display List?One button on my stage will addChild(radioButton) and another removes it. If the remove button is clicked first, then it obviously tries to remove something that has not yet been added and an error is returned. I've tried using the DisplayObjectContainer class with the contains() method to no avail.
The documentation for the List component at[URL].. states "A list can also display graphics, including other components," but nowhere can I find an example of HOW to make this happen. Can anyone please point me to a working example, I really need to be able to leverage this functionality, but I cannot for the life of me find anywhere it's being done.
i have this really basic class and all it does is create a button...i have another class called main where i want to put the button on the stage...problem is it all compiles but can't get the button to display..
public class Main extends Sprite { public function Main() {
I'm working on a game that has many elements on stage, so I'm looking to optimize my loops. I know that Vector is faster than looping an array, but I'm also in some cases using:[code]My question is when I use getChildAt, is that accessing an Array or Vector or linked list or other? Should I instead store references to my objects in a Vector and loop through that instead?
Is there a way to make a display object always be at the top of the display list?For example, I know you can set the childIndex, i.e:setChildIndex(myDisplayObject, numChildren-1);But is there a way that an object has sensed that something else has been added to the display list and restack themselves accordingly?
How do i add to a display list thats already has items on it?
this is what I have already
ActionScript Code: public function LotteryDraw() { // get the display list positions for each MC and text field... var startButton = this.getChildAt(0);