ActionScript :: Instantiate A Sprite Subclass That Adds Itself To The Stage?

Dec 31, 2010

I've created a wrapper around Sprite called ClickableCircle, which is meant to add itself to the display list when instantiated. Here's a toy version:

public class ClickableCircle extends Sprite {
protected var circle:Shape;
protected var myName:String;

[code].....

View 2 Replies


Similar Posts:


ActionScript 3.0 :: Instantiate Subclass With String?

Mar 18, 2010

I have some classes: LowA, LowB, LowC, SpaceShip, that all subclass BaseChar. How can I instantiate one of the subclasses by using a string for the name. (I have been trying to get this to work for a couple of hours now). For example, the typical way that I have been instantiating the subclasses:

[Code]...

View 2 Replies

ActionScript 3.0 :: Target Sprite From Subclass?

Jan 12, 2012

I create a Sprite in a subclass, add it to the stage. Now I need to target it from another class, but I am going wrong somewhere. This is shorten code, so hope I did not delete some important parts. But you should be able to follow the basic structure.

Main class:

package myClasses
{
import flash.display.Sprite;
import flash.display.Stage;

[code]...

View 3 Replies

ActionScript 3.0 :: Height/Width For Sprite Subclass?

Jul 26, 2009

For example, if I say:

ActionScript Code:
public class Chart extends Sprite {
public function Chart(myHeight:Number, myWidth:Number) {

[code]......

View 4 Replies

ActionScript 3.0 :: Width/height As Parameters To A Sprite Subclass

Jul 28, 2009

In a previous thread I asked a question about setting the width and height of a sprite subclass in its constructor method. One of the responses has puzzled me since I read it:
 
"Setting width and height only makes sense if you're adjusting the width and height of existing content, and the Chart (Sprite) has none at that point."
 
I don't understand that; what if you're adding children to the sprite that depend on those dimensions?
 
Here's a simple app which draws a red circle inside of a blue box which demonstrates my confusion as well as one other issue. The full questions are at the bottom.
 
Main.fla:
import Box;
var myBox:Box = new Box(200, 200);addChild(myBox);myBox.drawCircle();

[Code].....
 
Question 2: In this example, the dimensions of Circle are based on the width of its parent Box sprite. Is there a more elegant way to pass the dimensions to the circle? I ask because in my actual project (a chart) the plot area contains a lot of screen locations that must be passed around when I add new objects such as grid lines and markers and passing around the coordinates as parameters seems awfully messy. I'm just not sure how else to do it.

View 1 Replies

Actionscript 3 :: Add A Sprite From A Subclass To The Display List Of Its Super Class?

Aug 15, 2010

Say i have these two classes:

MAIN.as

package
{
import flash.display.*; import mx.core.*;
import flash.events.*; import mx.collections.*;

[Code]...

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.

View 2 Replies

ActionScript 3.0 :: AddChild Adds Only To The Stage, Not Nested MC

Jun 8, 2009

I have a class that adds to the main stage fine, but not inside an MC

var SliderTestClass = new SliderTestClass;

mContent01.addChild(issSlider); //trace says undefined
addChild(issSlider);//trace says [object SliderTestClass]

Why would it refused to be added to mContent01 which is a visible MC on the stage?

View 8 Replies

ActionScript 3.0 :: PrintJob Adds A White Rectangle To Stage

Oct 23, 2009

I currently have a button that triggers an event merging the movieclips on stage into one sprite, and passing it to a printer class. The printer class looks as follows:

ActionScript Code:
public class Printer {
private static var printJob:PrintJob = new PrintJob();
private static var printJobOptions:PrintJobOptions = new PrintJobOptions();

[Code]....

The problem is that when clicking the button, the stage gets a white rectangle in the upper left corner that can't be removed!

View 1 Replies

ActionScript 3.0 :: The Child Swf Has Code Which Adds Events To The Stage Object?

Nov 2, 2009

I have a movie, which on the click of a button will load a child swf.

The child swf has code which adds events to the stage object.

the child also accesses properties such as stage.stageWidth

When the child is ran on it's own all is fine, though when it loads within the parent movie i receive the error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.at Home()

"Home()" is the name of the document class in the child SWF.

a) access the stage from a child swf

b) add events to the stage from a child swf

View 2 Replies

ActionScript 3.0 :: Put An Extended SubClass On Stage?

May 12, 2010

I'm running into the situation where I can't instance a SubClass in the above SuperClass because the SubClass is extending from the SuperClass.
 
I get stack overflow. Fair enough, right?
 
Well, I want to add this SubClass to the display, and the only way I know how to do that is through addChild(). To addChild() I need to instance the SubClass.
 
I can't put any visual display instance or events in this subclass because it's currently null and extends is keeping me from doing so. It's great cuz I can share all the goods, but now I'm stuck dancing inside functions because I can't use events on the main "timeline" of the null SubClass.

View 1 Replies

ActionScript 3.0 :: Flash - Get To Run The Stage In A Subclass?

Sep 28, 2010

I try to run the function stage in class it is not working.

Code:
package devilClass.Player{
import flash.display.*;
import flash.events.*;

[Code].....

Is there a way to call class stage in a class Import?

View 2 Replies

ActionScript 3.0 :: Reference Stage From Within A Subclass?

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

ActionScript 3.0 :: Accessing A MovieClip On The Stage From A Subclass?

Jul 11, 2010

In my flash document, I have a movieclip drawn on the flash stage (put there myself, not dynamically). I want to use this as a holder for an external .swf. I am using a sub-class to run the loading script. I pass the stage reference to it as the variable "theStage". It has no trouble loading things directly to the stage, but it can't find my movieclip for some reason. I have exported the movieclip for actionscript in the symbol properties panel and have given it an instance name.I've tried theStage.myMovieClip.addChild(mySwf); and suchlike, but always get this error message in output:ReferenceError: Error #1069: Property myMovieClip not found on flash.display.Stage and there is no default value.at MethodInfo-206()Some more information: It works from the main class without any trouble.

View 1 Replies

ActionScript 3.0 :: Use Stage SubClass As Root / Parent

Dec 19, 2010

Is there a way to tell flash to instantiate a Stage subclass called "TheStage" instead of the default Stage class as root/parent of my document class?
public class TheStage extends Stage{
//code
}

Then when I do "DisplayObject.stage" I want it to return the instance of TheStage instead of the default Stage insteance. I want to do this so that I can override the addEventListener method of the Stage class. So if I call DisplayObject.stage.addEventListener I can execute my own code routine. Is that possible and how?

View 8 Replies

AS3 :: Flash - Reference SubClass Of SubClass From Parent Without Instantiating?

May 1, 2011

Can I access a static variable of a subClass' subClass? I don't want to instantiate it, just looking to get the variable because it has already been initialized by the subClass.example:

package
{
public class A extends MovieClip {
private var classB:B = new B();

[code]....

View 3 Replies

ActionScript 3.0 :: Sprite Won't Display On Stage

Aug 27, 2011

I'm sure you're expecting me to have forgotten to use addChild. I wish it was that easy. I will say I'm very new to AS3.0. I have a movie clip in my library that contains a small PNG file and a text label. The linkage properties are: Class: shapes.HorizontalIcon, Base class: flash.display.Sprite.[code]As far as I can tell this should work. There are no errors. The trace statement above shows up in the output. The parent sprite is also an item from the library. It shows up on the stage. I tried adding a random TextField to the parent sprite it showed up on the stage just fine.Something isn't working right, but I don't know where to start debugging this.

View 7 Replies

ActionScript 3.0 :: Create Several Sprite On The Stage?

Nov 15, 2010

ActionScript Code:
var MapBtnArray:Array = [];
var MapBtnSprite:Sprite;
var i:int;

[Code].....

I'm using to code above to create several sprite on the stage, but when I click on the sprite, the index of each trace work just fine (output of J is according to the target i click); however MapBtnArray[j].x keep equals to "0"

I want the coordinate of the sprite on stage, how come what i get is "0" instead?

View 1 Replies

ActionScript 3.0 :: Sprite Loader From Library Onto The Stage?

Jan 30, 2009

Loading a Sprite or MovieClip from the library to the Stage is simple. You just export the symbol and do the following code:

var mySp:Sprite1 = new Sprite1();
addChild(mySp)

assuming the exported sprite is called "Sprite1" and the base class is flash.display.Sprite

But what if you have many sprites and want to encapsulate this into a function with the sprite name passed as a string? What would the code in the function look like? Somehow you have to cast the string as the name of the sprite class defined in your export but I'm not sure how. I've seen a sample using the "as" keyword but try searching "as" in the help you you don't get much help.

Code:
function loadSpriteFromLibrary(sSpriteName:String)
{
//load the sprite with an exported name passed into sSpriteName onto the stage
//what would the code look like?
}

View 2 Replies

ActionScript 3.0 :: Align Center A Sprite In Its Stage?

Jul 8, 2009

I try to align center a sprite container in the center of the stage.

What can be the method to do it?[code]...

View 5 Replies

ActionScript 3.0 :: Firefox 3.6.8 - Sprite Missing From Stage?

Sep 2, 2010

I have a Flash website that I have tested in various browsers on my laptop, and it looks fine. I tested it on another PC in Firefox 3.6.8 (same version as my laptop) but for some reason, there is a sprite missing from the stage. On the same PC, the website looks fine in IE8. The vanishing sprite aside, the whole site is kind of sluggish in Firefox. The PC is kind of slow and old, but I can't see why that would cause images to vanish.

View 1 Replies

Actionscript 3 :: Maximum Stage And Sprite Size?

Oct 29, 2011

I'm making an action game and I'd like to know what should be the maximum size of the stage (mine is 660 x 500).Also I'd like to know how big a game-sprite should be. Currently my biggest sprites have a size of 128 x 128 and I read somewhere on the internet that you should not make it bigger because of performance issues.

If you want to make e.g. big explosions with shockwaves even 128 x 128 does not look very big. What's the maximum size I can definitely use for sprites?

View 2 Replies

Actionscript 3 :: Sprite Added To Stage But Not Visible?

Nov 30, 2011

I'm trying to get a simple AS3 app up and running, and for some reason, I cannot get a sprite to show. At this point, all I want to do is get a red sprite to fill the stage.

public class Main extends Sprite
{
public function Main():void

[code].....

View 2 Replies

ActionScript 3.0 :: Maximum Stage And Sprite Size?

Oct 29, 2011

I'm making an action game and I'd like to know what should be the maximum size of the stage (mine is 660 x 500). Also I'd like to know how big a game-sprite should be. Currently my biggest sprites have a size of 128 x 128 and I read somewhere on the internet that you should not make it bigger because of performance issues. If you want to make e.g. big explosions with shockwaves even 128 x 128 does not look very big. What's the maximum size I can definitely use for sprites?

View 4 Replies

IDE :: Creating A Sprite, And Adding 100 Instances To The Stage

Jul 16, 2009

I thought would be coded like this:

var sp:Sprite = new Sprite();
sp.graphics.beginFill(0xFF88CC);
sp.graphics.drawCircle(0, 0, 50);

[Code].....

however, I realize even tho im looping that addChild method, its still adding sp, so do I add a new naming convention in the loop, or should I be adding these instances to another display object.... this seems like such a simple thing to do yet I cant figure it out, I also want to randomize the x and y, but this first seems to be the issue I need to address.

View 1 Replies

ActionScript 3.0 :: Flash - Coordinate Of The Sprite On Stage?

Nov 15, 2010

PHP Code:

var MapBtnArray:Array = [];
var MapBtnSprite:Sprite;
var i:int;[code].....

I'm using to code above to create several sprite on the stage, but when I click on the sprite, the index of each trace work just fine (output of J is according to the target i click); however MapBtnArray[j].x keep equals to "0".I want the coordinate of the sprite on stage, how come what i get is "0" instead?

View 3 Replies

Flex :: Sprite Scaling Children Even Though Stage.scaleMode = "noScale" And Stage.align = "TL"?

Aug 6, 2010

I am creating an AIR nativeWindow. I am adding two children, an HTMLLoader and a Sprite. The child Sprite has two children, a TextField and a Sprite that will be used to draw. I have set stage.scaleMode = "noScale" and stage.align = "TL", which the HTMLLoader seems to respect. However, the child Sprite scales its children whenever I set a height.

public function BaseWindow(){
var winInit:NativeWindowInitOptions = new NativeWindowInitOptions();
winInit.type = NativeWindowType.NORMAL;[code]..........

How do I prevent the distractor Sprite from scaling its children?

View 1 Replies

ActionScript 3.0 :: When To Remove Child - Sprite To Stay On The Stage Until One Of Two

Dec 16, 2008

I have a map with various regions as movieclips. When you mouse over a region, a sprite appears containing xml data. Among this data is a hyperlink. I want the sprite to stay on the stage until one of two
things happens:

- you mouseout of the sprite
- you go to a new region

That seems to be the problem. I've successfully coded the program to remove the child if you mouseout of the sprite. But if you go to a new region, it makes a new sprite and now you have two sprites with xml data on the stage! If I remove the child when you mouseout of the region, then the sprite won't stay on the stage for you to click the hyperlink. How can I make the sprite stay on the stage until:

- you mouseout of the sprite
- you mouseout of the region IF you aren't on the sprite

View 5 Replies

ActionScript 3.0 :: Specify The Sprite Height/width To Match The Stage?

Oct 28, 2010

I got a screen to display objects in a sprite that covers the stage. ok I got a screen to display objects in a sprite
 
q1) do I need to specify the sprite height/width to match the stage or is this implied with canvas1=new Sprite();addChild(canvas1);

[Code]....

View 5 Replies

ActionScript 3.0 :: EventListener - Select / Deselect Sprite On Stage

Oct 26, 2010

I have the following code:
Code:
btn.addEventListener(MouseEvent.CLICK, select);
function select(evt:MouseEvent):void {
addEventListener(MouseEvent.CLICK, unselect);
} function unselect(evt:MouseEvent):void {
removeEventListener(MouseEvent.CLICK, unselect);
}
The idea is to be able to select the "btn" sprite and while it is selected you can click anywhere on stage to deselect it. I thought this would work but somehow after a single mouse click it also executes the unselect function. Since I add this function after the mouseclick I do not understand why it is doing this. Is this not the way to do such a thing?

View 6 Replies

ActionScript 3.0 :: Sprite Not Loading Onto Stage From Class File

Sep 21, 2011

For the life of me I can't work out why this script is not working: In the library are two movieclips: pink_sprite and green_sprite each of which has a attached class pinkSprite and greenSprite. These classes in turn are extenders of the hitTest.as class below.

[Code]...

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved