ActionScript 3.0 :: Height/Width For Sprite Subclass?
Jul 26, 2009For example, if I say:
ActionScript Code:
public class Chart extends Sprite {
public function Chart(myHeight:Number, myWidth:Number) {
[code]......
For example, if I say:
ActionScript Code:
public class Chart extends Sprite {
public function Chart(myHeight:Number, myWidth:Number) {
[code]......
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.
I created a class, extended the sprite class, and now in the constructor I am trying to set the Sprite's width and height properties which are inherited from the DisplayObject. However, after I set this.width and this.height, and print the values, I get 0 for both.
What the heck is going on? When I view the livedocs I see that DisplayObject has width and height listed as public properties. I have been able to instantiate a Sprite directly, and set the width and height after it's been instantiated, so I don't get it.
package {
import flash.display.*;
public class ScrollBar extends Sprite {[code].....
What is the maximum height and width of a sprite.
View 7 RepliesHere is some code I have.
[code]
_buttonUnderline = new Sprite();
with(_buttonUnderline.graphics) {
[/code].....
When the Tween takes place though it not only changes the width, it changes the height as if it were scaling it up in both directions. Why does this behavior take place? And how can I get it so that only the width changes? I have also tried using scaleX as the property but it does the same thing.
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]....
Given this code:
[Code]...
Why does changing the width and height of uiComp not affect the Sprite? Wouldn't UIComponent provide Sprite with a Graphics object, which limits that area where Sprite can draw?
I'm working with a Sprite in AS3. Initially, width,height are 0,0 as expected.
After this:
var tf : TextFormat = new TextFormat();
tf.font = "Arial";
tf.size = 48;
[code]....
I know this might seem like such an easy issue and I can't understand why I cant figure it out but none the less I can't and I've just about given up. Here's the issue:
I have a sprite container which is supposed to hold a bunch of thumbnails to videos. I am able to populate the container with all the videos and the whole works but obviously if I add a bunch of videos its going to exceed the size of the flash document so I need to add a UIScrollBar (which I did) now the scrollbars target is set to the container but isnt allowing me to scroll and if im correct this is because the container doesnt have a set height. So Im trying to set the height of this container but the second I try setting the height or even width all my thumbnails I used to be able to see are gone! It's as if the size is being set to 0 when its not I've even tried to set it to a specified size just to test and nothing.
[Code]...
[code]When the Tween takes place though it not only changes the width, it changes the height as if it were scaling it up in both directions. Why does this behavior take place? And how can I get it so that only the width changes? I have also tried using scaleX as the property but it does the same thing.
View 1 RepliesIs it possible to set the height of the sprite depending on the height of an textfield inside that sprite? I'm creating a box with a textfield inside it, but I want the box to be sized depending of how much text it is in the textfield..
View 9 RepliesI am trying to reference to top level (stage) width and height of the main stage for the placement of something located inside a movieclip on the stage.
My code is:
Code:
my_loader.x = (stage.stageWidth - my_loader.width)/2;
my_loader.y = (stage.stageHeight - my_loader.height)/2;
But this seems to just relate to the width/height of the mc that my_loader is nested in...
I have tried the following and had no luck:
stage.stage.stageWidth
root.stage.stageWidth
parent.stage.stageWidth
MovieClip(root).stage.stageWidth
i want to load external images of different height and width into same height and width.
View 3 Repliesi want to load external images of different height and width into same height and width.
View 0 RepliesI would like to use a movieclip to load a flv video. The problem I have is that I want to change the video dimensions. I've tried several software to change the video dimensions but as far as it seems all of them keep the same height-width ratio than in the original video. Is there any software that would allow me to change the height and width without keeping the same height/width ratio as in the original video file?
View 1 RepliesI 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]...
Both of sprite.width and sprite.scaleX can be used for scale a sprite. Is possible sprite.scaleX depends on screen size?
View 2 RepliesIt has been a great resource of the years. No my problem. I am trying to dynamically resize a sprite that has a line drawn into it. Here is my code:
[Code]...
I would like to use a movieclip to load a flv video. The problem I have is that I want to change the video dimensions. I've tried several software to change the video dimensions but as far as it seems all of them keep the same height-width ratio than in the original video. Is there any software that would allow me to change the height and width without keeping the same height/width ratio as in the original video file?
View 3 RepliesI'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].....
I am looking at the SimpleButton entirely wrong. Here's what I'm doing (inside of a MovieClip):
[Code]...
the close_btn.width and height remain 0. Am I supposed to just rely on the DisplayObject members of the SimpleButton completely and ignore width/height/x/y or what?
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.
I have a flash banner graphic that I created at 1000px wide by 420px tall. I want this to be fluid and fill the browser width, so that when the browser is rescaled the swf fills the horizontal space. My problem is that there is content below it that needs to touch it, but the height is trying to fill 100% so it is creating vertical space between the flash content and the div below it.
I guess a better way to describe it is that I don't want to define the height I just want the width to be 100%. At 100% height there is unused space so I need to make the height maybe undefined or something smaller then 100%?Also, if you make the browser too small vertically the width will not fill. So I want 100% width regardless of the browser height.
How do I set the width and height of my swf in AS3?
This is my code so far:
package {
import flash.display.Sprite;
public class Game extends Sprite {
}
}
Right now, when loaded it is at some arbitrary default size.
If I can't change the size this way, is there any easy work around that will be consistent?
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]....
my .swf goes full screen and changes proportion if it is accessed directly at it's url
[URL]
is it possible to tell how big it currently is? i'd like to reposition some elements accordingly...
I'm trying to change the position of a movieclip I've added to the stage. When I try to access stage.width or stage.height I get 0. I've tried MovieClip(root).stage, DisplayObject(root).stage, root.stage, stage, and simply width and height. All of these are equal to zero.
View 1 RepliesI want to write a shell that creates instances of an app and scales it down for animating. Well, I created my shell class and instanced the app and set scales for x and y and then I traced the height and width because I wasn't sure what they'd be. I thought they'd be based on the stuff on the stage or whatever, but they both came up zero. So I'm not sure how that works, am I supposed to have set those values?
[Code]....
I have an empty movieclip in the stage that holds a backgroundbg._width = Stage.width;bg._height = Stage.height;the background is loaded from XML and works fine since I'm not set the width and heightbut if I set: bg._width = Stage.width and bg._height = Stage.height
View 1 RepliesI have two Canvas A and B, A is the child of B.A can be resized by some user actions like adding some UI components to its base.A is bounded by an other Parent canvas B which should show scolling handles if its child A gets too large.I would like A to have the same width and height of B (or really close) while the calculated width and height of A is smaller than those of B.If w or h of A get larger than those of B then A should grow and B will show scrolling.
View 2 Replies