Subclass Flash TextField In MX2004 Pro?
I am building a form based data driven application using Flash MX 2004 Professional and would like to create all my TextInput components using a subclass of the standard Flash TextInput. I have found many examples of subclassing a MovieClip component but none showing how to subclass other components.
The basic idea is that my application will have around 300 text input components. If I can create these by subclassing the Flash TextInput, if I ever want to change the back color, font color, etc for all the input components, I can do it by modifying the subclass only. I also want to build security at the individual text input level so having them all instantiated from a common subclass would make this much easier to maintain. Anybody know of a tutorial online that shows this or can give me some pointers?
Thx!
Tek-Tips > Adobe(Macromedia): Flash Forum
Posted on: 28 Feb 04 13:20
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
[AS3] Textfield In A Subclass
Hi
I'm working on a AS3 Project in Flex 2 and I've been looking for hours for a solution to a (I'm sure very simple) problem: it's a pure AS3 Project, so no mxml file, and I try to output text in a textfield created in a subclass. I've read a lot of posts and the documentation and whatever I could get hold of, but it only outputs when I define the textfield in the main application class.
If I define the field in a subclass, which is imported properly in the main class with the "new" statement instantiated, nothing happens. To illustrate it, take these examples:
Works perfect:
Code:
package {
import flash.display.Sprite;
import flash.text.*;
public class whynot extends Sprite
{
private var display_txt:TextField;
public function whynot()
{
display_txt = new TextField();
display_txt.text = "a text";
addChild(display_txt);
}
}
}
No output from this:
Code:
Filename: whynot.as (the main application class):
package {
import flash.display.Sprite;
import OutputTheThing;
public class whynot extends Sprite
{
private var theText:OutputTheThing;
public function whynot()
{
theText = new OutputTheThing();
}
}
}
Filename OutputTheThing.as:
package
{
import flash.display.Sprite;
import flash.text.*;
public class OutputTheThing extends Sprite
{
private var display_txt:TextField;
public function OutputTheThing()
{
display_txt = new TextField();
display_txt.text = "a text";
addChild(display_txt);
}
}
}
Any ideas? I feel very stupid, I must have missed some basic idea of actionscript programming.
Thanks for any help,
Phil
OOP Dilema - To SubClass Or Not To SubClass. That Is The Question.
Hi ppl,
I've been working on this script --> http://www.geocities.com/amirdotan/stuff/songList.html
which creates a song list and allow the user to make his own based on the original list. I am using one MC and one Button and using the songClass to set the properties of the movie clip according to its "type" (song to choose to song that was chosen").
It works just fine but as you can see, inside the songClass I am using an if conditions twice, once in the setColor function and then again when I have to decide on the button's action. This might hold for now but if I'll have 10 different types I can not have 10 ifs or cases. So I'm asking you how would go about and upgrading this?
I'm thinking I can have each type as a subClass but before I do that I seek a 2nd opinion
Thnx,
McMurphy
Problems With MX2004 Textfield Component.
I have used Flash's (MX2004) textfield component.
I want it not to be selectable.
I've tried naming my text field testString and have tried using the following code:
testString.selectable = false;
testString.text.selectable = false;
Neither of the above work.
I've also changed the components parameters... but that doesn't have any effect either!
See the following links for the fla and swf:
http://www.filmcharts.com/testString/testString.fla
http://www.filmcharts.com/testString/testString.swf
(The FLA was slightly too big to upload.)
Any help would be appreciated.
Thanks.
OM
Attaching A Textfield To A Window Component In Mx2004?
this might be the wrong forum; however...
I'm trying to build a window component that will pop up and display the news in a textfield. i THOUGHT creating a new object with a window component and a textfield component on top of it would work; unfortunately, when i drag the window around, the textfield stays where it's at...
any suggestions here?
thanks in advance
[MX2004] How To Update Textfield Only When Changed? - Urgent
I have 2 textfields...
They have to be related to each other so when I change the data in one of them, the other changes too (not identically... calculations and stuff)
And when I change the second one the, first one has to change accordingly... like a 2-way thing
Has that something to do with listeners mby? Never used them b4
[MX2004] How To Update Textfield Only When Changed? - Urgent
I have 2 textfields...
They have to be related to each other so when I change the data in one of them, the other changes too (not identically... calculations and stuff)
And when I change the second one the, first one has to change accordingly... like a 2-way thing
Has that something to do with listeners mby? Never used them b4
Customizing The Appearance Of The TextField Component In MX2004 Professional
I'm trying to change the look of the text input component to get rid of all the drop shadow effects and be left with only a light gray 1px border.
I've used this actionscript:
Code:
_global.style.setStyle("borderColor","0xCCCCCC");
_global.style.setStyle("borderCapColor","0xCCCCCC");
_global.style.setStyle("highlightColor","0xFFFFFF");
_global.style.setStyle("shadowColor","0xFFFFFF");
_global.style.setStyle("shadowCapColor","0xFFFFFF");
Everything works fine, however I am always left with a darker 1px border along the top of the component. No matter what I do, I can not change that top border color. All of the documentation I've found says that the borderColor setting should control that portion of the component, but it will not work.
Have any of you run across this problem before? Any ideas how to fix it?
5000: The Class 'gallery' Must Subclass 'flash.display.SimpleButton' Since It Is Link
I have a class that extends MovieClip and I am receiving this error...
Code:
5000: The class 'gallery' must subclass 'flash.display.SimpleButton' since it is linked to a library symbol of that type.
If I change the extends MovieClip to Extends SimpleButton - the error goes away but then I errors about calling addChild method being undefined...
A bit of a lose lose - any hints?
Subclass Of MovieClip Or Not~
howdy~
i used to AS1 and now i'm trying to code with AS2 with my small project, and i write a simple class Sun to perform some actions on certain movieclip on the stage, and here is the definition of the class:
Code:
class Sun
{
private var __radius:Number;
public function Sun()
{
__radius = _width >> 1;
}
public function get radius():Number
{
return __radius;
}
public function set radius(r:Number):Void
{
_width = r << 1;
_height = r << 1;
__radius = r;
}
}
all works great but i had 2 questions here:
1. what about the difference if i inheritance the Sun from MovieClip explicitly with the code like this below:
Code:
class Sun extends MovieClip
{
// ...
}
i have this question because my Sun class works fine for mcs on stage and it seems useless to make Sun inherited MovieClip.
2. i had a mc with instance name "sun" on the stage, and it goes well with the Sun class above. but i have no idea how to pass parameters to Sun's constructor so that i can change properties of instance "sun" when it was rendered on the screen. how can achieve this plz ?
thanx~
Subclass A Singleton
does that even make sense? I wanted to add some situation specific methods to an otherwise generally usable singleton class, and was wondering how I would subclass it. Or if that's even possible in the fist place. I mean normally, the superclass's constructor would get called but I assume that's not the case with singletons? And the from there on, it's all just kind of awkward.
Movieclip Subclass
Hi I'm trying to write a movieclip subclass. When an object is instantiated It needs to appear on stage.
Map.as
Code:
dynamic class Map extends MovieClip{
private var _imageUrl:String;
private var _xLoc:Number;
private var _yLoc:Number;
private var _zoomFactor:Number;
private var Map:MovieClip;
//constructor
public function Map(p_imageUrl:String, p_xLoc:Number, p_yLoc:Number)
{
this._imageUrl = p_imageUrl;
this._xLoc = p_xLoc;
this._yLoc = p_yLoc;
_zoomFactor=50;
}
/*other methods*/
}
now i want the map to apear on stage with the following line
fla file:
Code:
var viceCity:Map = new Map("image/ViceCityMap.jpg",100,100);
Does anyone have an idea i've looked through some tutorials but i cant make it work.
Subclass Cannot See Main
hello, im creating some kind of game, that has an movieclip on the first frame, which holds the main class of the game. It creates a instance of a ship. When a button is pressed the main class creates a movieclip that has an own class. That class should do like this: this.lineTo(ship.x,ship.y);
But however I do it cant find the ship instance and tells me that its null.
If someone really wants to help me, and is good at as 3, add my msn: aksel_92lever@hotmail.com
Thanks.
Subclass Problem
I'm testing some Papervision3D stuff, and I have this bitmap on the library and with this class: FlashIcon
ActionScript Code:
package
{
import flash.display.Sprite;
import flash.events.*;
// papervision 3D classes
import org.papervision3d.cameras.*;
import org.papervision3d.materials.*;
import org.papervision3d.objects.*;
import org.papervision3d.scenes.*;
public class FlashIcon extends Sprite
{
public function FlashIcon ()
{
// container
var sp:Sprite = new Sprite();
sp.x = stage.stageWidth * 0.5;
sp.y = stage.stageHeight * 0.5;
addChild(sp);
// adding PV3D elements
var scene:Scene3D = new Scene3D(sp);
var cam:Camera3D = new Camera3D();
cam.zoom = 5;
// setting up BitmapAssetMaterial ( actually gets the material from the library)
var bam:BitmapAssetMaterial = new BitmapAssetMaterial("FlashIcon");
bam.oneSide = false;
bam.smooth = true;
// adding the actual obecjts to the 3D scene
for (var i:uint = 0; i<50; i++) {
var p:Plane = new Plane(bam, 123, 87, 2, 2);
scene.addChild(p);
p.x = Math.random() * 1000 - 500;
p.y = Math.random() * 1000 - 500;
p.z = Math.random() * 1000 - 500;
p.rotationY = Math.random() * 360;
}
this.addEventListener(Event.ENTER_FRAME, render);
function render(e:Event):void
{
trace("frame entered");
cam.x += stage.mouseX - (stage.stageWidth*0.5);
cam.y += stage.mouseY - (stage.stageHeight*0.5);
scene.renderCamera(cam);
}
}
}
}
And I keep getting this error:
5000: The class 'FlashIcon' must subclass 'flash.display.BitmapData' since it is linked to a library symbol of that type.
Help Creating A Subclass
Hi
Im in the progress of creating a XML menu component, and Im going well so far. My code is a bit messy and currently for the button press actions for the menu items I have done this below:
(a method used by Senocular in the xml menu tute)
ActionScript Code:
Actions = Object();Actions.loadGallery = function(xml, name) { _root.transfer = new Object(); _root.transfer.galleryData = xml; _root.transfer.galleryLabel = name; _root.content_mc.target_mc.loadMovie("gallery.swf");};Actions.gotoURL = function(url, name) { getURL(urlVar, "_blank");};Actions.message = function(msg, name) { message_txt.text = msg;};Actions.newMenu = function(menuxml, name) { menu_xml.load(menuxml);};
This is just sitting in my main class (called XMLMenuClass) and is not a prototype as you can see, I would like to know how to reimplement this as a class of its own,ie a subclass of the main class called MenuActions?
Thanks in advance
SubClass Variables
1: Is there a way to set superclass variables from within a subclass?
I can't seem to accomplish it.
2: Also, why does it seem when I call a function, the superclass version is called instead of the sub? I construct the class using the sub, so whats the matter?
3: In one of the classes, I want to push a MovieClip it creates into an array, it works, but I get an undefined, then the value.
4: I have 3 levels of inheritance in my classes Specials -> Human -> Player, who do i call each one correctly from one another?
Thanks for any and all help, I really appreciate it
Movieclip Subclass?
Hi,
I have several different AVIs which I have imported as movieclips.
I want to be able to have some common functions for the different clips which will for example start them playing at the same position.
For example if I have five different car avi movie clips, I would like to have a funciton AnimateDriving() or StopDriving() which I can invoke for each car (maybe from a super class) which executes the same code (eg gotoAndPlay(5)).
I know I can use MovieClip.prototype but this in not really OOP
and most websites i viewed say this is wasteful, as I have many other different (non-car) movieclips.
Can anyone suggest the best way to do this.
Much appreciated.
DumbMonkey.
Access The SubClass.. Is That Possible?
Hello again,
I'm trying to check if there's any subclass from inside the body of a default class. Is that possible in AS3? I imagine it could be something like the 'super' statement, but a 'sub' one..
Anybody has experience on that?
Tanks a lot.
Help Creating A Subclass
Hi
Im in the progress of creating a XML menu component, and Im going well so far. My code is a bit messy and currently for the button press actions for the menu items I have done this below:
(a method used by Senocular in the xml menu tute)
ActionScript Code:
Actions = Object();Actions.loadGallery = function(xml, name) { _root.transfer = new Object(); _root.transfer.galleryData = xml; _root.transfer.galleryLabel = name; _root.content_mc.target_mc.loadMovie("gallery.swf");};Actions.gotoURL = function(url, name) { getURL(urlVar, "_blank");};Actions.message = function(msg, name) { message_txt.text = msg;};Actions.newMenu = function(menuxml, name) { menu_xml.load(menuxml);};
This is just sitting in my main class (called XMLMenuClass) and is not a prototype as you can see, I would like to know how to reimplement this as a class of its own,ie a subclass of the main class called MenuActions?
Thanks in advance
AS3 - Access The SubClass.. Is That Possible?
Hello again,
I'm trying to check if there's any subclass from inside the body of a default class. Is that possible in AS3? I imagine it could be something like the 'super' statement, but a 'sub' one..
Anybody has experience on that?
Tanks a lot.
Access The SubClass.. Is That Possible?
Hello again,
I'm trying to check if there's any subclass from inside the body of a default class. Is that possible in AS3? I imagine it could be something like the 'super' statement, but a 'sub' one..
Anybody has experience on that?
Tanks a lot.
MX AttachMovie Within Custom Mc Subclass
I am trying to create a panel for an interface. This panel is a subclass of MovieClip and is registered. The problem is that when i use this.attachMovie(...) it doesn't work, i can use _root.attachMovie(...), but that isn't going to work at all when i instantiate a whole bunch of these guys. Can someone see my error?
Code:
_global.CPanel = function(){
}
// Set CPanel prototype chain to inherit from MovieClip
CPanel.prototype = new MovieClip();
// Register CPanel as the class for symbol "Panel"
Object.registerClass("Panel", CPanel);
CPanel.prototype.onLoad = function() {
var TL_Point = new CPoint(250, 100);
var BR_Point = new CPoint(300, 200);
this.Location_Rect = new CRect(TL_Point, BR_Point)
this.attachMovie(this.Contents_str, "Contents_mc", 33);
_root.Contents_mc._x = this.Location_Rect.GetTopLeft().GetX() + 1;
_root.Contents_mc._y = this.Location_Rect.GetTopLeft().GetY() + 20;
this.Draw();
}
Attach MC From Inside A Subclass
Hey,
How do I attach a MC from a function inside a subclass (the MC I want to attach is not the superClass of that subclass)?
Thanks,
MovieClip Subclass Withing Another One.
Hi,
Have a movie clip subclass A that has another movie clip subclass B as one of its attributes. Everything works correctly for now but when i want to handle events from the movie clip subclass B it does not work.
Am trying to handle onPress and when i click on my clip B it is the method onPress of the movie clip A that is called.
Any solution doctor ?
Any help is very very welcome.
PS. Hope i did not give u headaches with this little story
Parameters On Subclass Of Movieclip
I have an Actionscript class which extends MovieClip with a few functions and properties. I can set the class of any movieclip to this class and get the functions without problem, but how do I set the properties without writing actionscript on the instance itself?
I'm building this as a way to encapsulate the actionscript and make it easy for non-coding artists to create this functionality without having to do too much actionscript.
Ideally, I'd be able to set the properties in the properties or parameters tabs. There's going to be more than one movieclip of this type, with completely different graphics on them, so as far as I know, a component won't work. I'd be okay with creating a jsapi tool to set the properties, but that seems like overkill.
Can a behavior-only component be attached to a movieclip instance and 1) change the class of that movieclip and 2)set properties on that movieclip based on the parameters panel?
Or is there another way to approach this problem?
Subclass Function Not Getting Called.
This setup worked in AS2 but having problems making it work in AS3.
Super class
Code:
package com.scroller{
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.display.MovieClip;
public class MovieClipHandler {
private var canvas : MovieClip;
public function MovieClipHandler( canvas:MovieClip ) {
this.canvas = canvas;
setupAssets();
}
private function setupAssets() : void {
}
public function setPosition( value:Point ) : void {
canvas.x = value.x;
canvas.y = value.y;
}
public function getCanvas() : MovieClip { return canvas; }
public function getRectangle() : Rectangle {
return new Rectangle( canvas.x, canvas.y, canvas.width, canvas.height );
}
}
}
Sub Class
Code:
package com.scroller{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import com.scroller.MovieClipHandler;
public class ScrollTrack extends MovieClipHandler {
private var controller : Object;
private var canvas : MovieClip;
private var top : MovieClip;
private var middle : MovieClip;
private var bottom : MovieClip;
public function ScrollTrack( canvas : MovieClip ) {
super( canvas );
}
private function setupAssets() : void {
top = canvas.top;
middle = canvas.middle;
bottom = canvas.bottom;
addEvents();
}
public function setController( value:Object ) : void { controller=value; }
}
}
The setupAssets() method in the sub class is not getting called. In AS2 it gets called but not in AS3 any ideas why?
Instantiate AS2 Subclass Of MovieClip?
I can't figure this out. I have a simple class which extends MovieClip, something like this:
ActionScript Code:
class Box extends MovieClip{
function Box(size){
trace(size);
}
}
I have a library item associated with this class. How do instantiate this class and pass the size parameter?
Subclass Method Inheritance
Hellooo,
I have a class called Creature with method KillCreature.
I also have a class Enemy extends Creature
I seem to be having problems using Enemy.killCreature().
I do not wish to modify the killCreature() method in anyway, please help!
Displaying Sprite Subclass
Hi
I cant get my Sprite Subclass displayed.
What do I have to do to get Subclass on the Stage. I Add two other Sprites (s1.addChild(s2)) but on
s1:spriteSubClass = new spriteSubClass();
s1.addChild(s2); //s2 = "blue Rect" Sprite
root.addChild(s1);
Nothing will be displayed, by the way the width and height are not availible ( = 0)
the only way is to Draw a Graphic within the Subclass (beginFill ... drawRect ...endFill)
Then it will be displayed but with a wrong size (based on the drawRect order).
Are there some good examples for that case somewere?
What have I do to get it displayed without any drawings just after adding some MovieClips or Sprites...
I hope there is an easy solution for this, without any patchwork.
Thanks for all Answeres
[AS3] Custom Event Subclass
I'm having a problem with a custom subclassed Event class. Or I should say, I'm having trouble receiving events from this custom event class. I'm pretty sure I have everything wired correctly, the event is dispatched properly and my trace shows the Event instance being spawned. However, my eventListener, which is in another class, never fires its handler function.
Have any of you run across instances where custom event classes fail to fire? I'm about at my wit's end.
Subclass, Superclass Issue...
Hey Gang,
I have a superclass called "BaseWindow" that all my smaller windows in my flash app are extending.
All these windows have a movieclip as their background (basically just white with an orange border).
I want to be able to access the size of these backgrounds. I have given them all the name "window_mc" and in my BaseWindow class, in the constructor I added the line _bg = this.getChildByName("window_mc") as MovieClip;
So there shouldn't be an issue, but now when I compile I get a load of errors, the first being:
1152: A conflict exists with inherited definition windows:BaseWindow.window_mc in namespace public.
That error occurs on one of my windows. If I remove the "window_mc" from that instance of the window, the same error will come from another of the windows...
Can someone explain this to me?
Thanks,
--d
Subclass Parent Question
When instantiating a class from another class, if I want to access the "caller class" as a parent from within the subclass, do I always have to pass "this" as a movieclip to the constructor? I am kind of new to as3 and I am finding that to dispatch events how I want them many times I need access to the parent and this code does not work properly:
ActionScript Code:
var mc:MovieClip = parent as MovieClip;mc.method();
And if the best way to access the caller is by passing the caller as a movieclip through the constructor of the subclass, then why couldnt they have just made it an inherited property since its used so often?
Simple Subclass Experiment?
In the simple code below why is my subclass (MinorClass) not inheriting the transparancy from the superclass (MajorClass)? In brief the code pulls in movieClips from Library making "shape" a superclass (MajorClass) and giving it a transparancy of 30. But the transparency is not being inherited by the subclass "MinorClass".
MajorClass = function(){
this._alpha=30;
}
MinorClass = function(){
this.onEnterFrame= function(){
this._rotation+=5;
}
};
MajorClass.prototype = new MovieClip();
// is this making the subclass I require?
MinorClass.prototype = new MajorClass();
Object.registerClass("four", MinorClass);
Object.registerClass("square", MinorClass);
Object.registerClass("circle", MinorClass);
Object.registerClass("rect", MinorClass);
Object.registerClass("shape",MajorClass);
attachMovie("shape","shape",9)//This "shape" bit of text that is being attached
//code below just positions and attaches clips
shape._x=150;
attachMovie("four","four",10)
four._x=10;
four._y=100;
attachMovie("square","square",11)
square._x=100;
square._y=200;
attachMovie("circle","circle",12)
circle._x=200;
circle._y=200;
attachMovie("rect","rect",13)
rect._x=300;
rect._y=200;
Access To Stage From Subclass
hello,
i'm a bit stuck with something. i have a class that loads a bunch of thumbs. now i would like to reorder them when the stage is resized.
my problem is now that I get an error when I try to access the stage:
Code:
public function loadThumbs(stageW:Number, stageH:Number, stageRatio:Number, folder:String ) {
_xmlL = new XMLLoader (xmlPath + _folder);
_xmlL.addEventListener (XMLLoader.XMLLOADED, xmlComplete);
stage.addEventListener(Event.RESIZE, onResizeThumb);
}
in the fullscrollbar of onebyonedesign he also is doing this. my class extends Sprite.
can anyone help me with this?
Subclass A Class From Another Clip? -- URGENT, PLEASE
Hello.
Does anybody know how to call the constructor of a superclass when the subclass is defined in a separate movie clip?
This is what I have:
In clip _root.tester...
-------------------------------------
function classA () {
this.message = "hello";
this.getMessage = function () {return this.message;}
}
-------------------------------------
In clip _root.toTest...
-------------------------------------
function classB () {
this.superClass = classA //Look below for line variations
this.superClass(msg);
this.getExtdMsg = function () {return this.getMessage + ", world";}
}
classB.prototype = new _root.tester.classA;
-------------------------------------
My problem happens because the constructor classA isn't actually getting called in the second line of classB. I have also tried all the fullpath-variations I can think of:
this.superClass = _root.tester.classA;
this.superClass = _parent.tester.classA;
this.superClass = _parent._parnet.classA;
Create A Subclass Of Built-in Class
I would say that creating a subclass of built-in class is possible, but how?...
For example:
Code:
format1_fmt = new TextFormat();
format1_fmt.size = 10;
format1_fmt.align = "right";
//
format2_fmt = new TextFormat();
format2_fmt.size = 15;
format2_fmt.align = "right";
Instead of defining a new format (format2_fmt) from scratch, because both formats have the same "align", I would like it to inherit the properties from format1_fmt
MovieClip Subclass Listener Problem
I noticed a problem with MovieClip subclass instances that are created via associating the class to an mc symbol from the library. Attached code and files below.
EDIT: I think I located the problem... is it because onMouseDown is a built in method of the MovieClip class... are all MovieClip instances automatically added to the Mouse's listener list? ... if yes, I assume the line "Mouse.addListener(this);" a redundancy... I am assuming this because when that line is removed everything works correctly.
The problem is this... when I attach an mc to the stage and that mc's class adds it as a listener to let's say the Mouse, all event calls are made twice. This poses a major problem.
Anyone have any suggestions? ... is there a way to reference the symbol that represents a class from within the class api?
Code:
.as file:
Code:
class Test extends MovieClip {
public var counter:Number;
public function init():Void{
counter = 0;
Mouse.addListener(this);
}
public function onMouseDown():Void{
trace("MouseDown event recorded");
counter++;
trace(counter);
}
}
.fla file is attached to the post
[F8] Problems Making MovieClip Subclass. Help Please?
Okay, so this is my first foray into making some classes in flash. It will make my life so much easier. Some quick background, this will basically be a sprite object for a gamepiece in a turn based game. This is the generic ship, which will in theory then have it's own subclasses for specific pieces. I really want them object oriented as some will react differently to the same inputs. This should be a great place to use polymorphism.
My problem is that I can't seem to get inheritance working. I am thinking it might be because the MovieClip class does not have a constructor. Is this the problem? How do you write a constructor for a subclass whose superclass has no constructor?
Here is what I currently have (stripped down to just what is needed in this example):
AS file 'Ship.as'
Code:
class Ship extends MovieClip {
//public variables
private var _health:Number = 9;
private var _gridrow:Number = 1;
private var _gridcol:Number = 1;
//constructor
public function Ship(shiptype, shipname, gridrow, gridcol) {
gridrow = Number(gridrow);
gridcol = Number(gridcol);
//create movieclip
_root.canvas.attachMovie(shiptype,shipname,_root.canvas.getNextHighestDepth());
//set ship position (relative to canvas movieclip)
this._y = (_root.gridsize/2) + ((gridrow-1)*_root.gridsize) -10;
this._gridrow = gridrow;
this._x = (_root.gridsize/2) + ((gridcol-1)*_root.gridsize);
this._gridcol = gridcol;
}
}
Example of the code I am trying to use in my main movie:
('canvas' is a pre-existing movieclip instance)
Code:
var gridsize:Number = 64
var playership:Ship = new Ship("ship1","playership1", 2, 3)
playership._x = 200
playership._y = 200
trace(playership)
trace(playership._x)
What this does, is properly create the 'playership1' instance of the 'ship1' movieclilp, and puts it at position 0,0.
The code in the constructor to move the ship and the code in the main fla to set the _x don't move the ship though.
The response from the trace commands is:
[object][object]
200
From debugging I can see:
There is an object of some type called 'playership' that is created, and it's _x property is being set, but it is not moving the object like it would move a movieclip (like I would think it should due to inheritance).
There is also a 'playership1' movieclip instance being made, but it's _x is not being changed by any of the code.
Is there anyway I can get this to work how I would like? So I could treat the above 'playership' object like a movieclip but with additional methods to control how it moves around, how it reacts to damage etc... I keep thinking it is something wrong in the constructor, that I have to call the movieclip superclass constructor, but movieclip has no constructor.
Help please!
Referencing A Sprite Subclass's Properties
Hi there allow me to begin explaining my confusing.
Class A extends Sprite {}
Say we want to create a list of A objects on screen. 1 below the other.
var array:Array = new Array();
for (var i:int = 0; i < 10; i++)
{
var a:A = new A();
addChild(a);
if (array.length > 0)
{
a.y = array[i-1].y + array[i-1].height;
}
}
Im not sitting infront of Flex or Flash just now, but you get the basic idea.
In my project, these are news Items loaded with XML, if i trace inside the A class, i can do
trace(this.height) //160;
however, when i do this on the same object outside the class
trace(a.height) //0;
Incredibly frustrating!!
The A class is on the stage, i physically can see it there and it looks about 200px high so why is its height property returning as 0?
Thanks
Cannot Access Superclass Static Var From Subclass In FLA
I have come across something that to me doesn't seem correct and I don't know why things are behaving this way. I have 2 classes, one a subclass of the other. Both have public static variables (AS2.0 Flash 7).
Code:
class mypackage.Fruit {
public static var COLOR:Number = 0;
}
Code:
class mypackage.Orange extends mypackage.Fruit {
public static var SEEDS:Number = 0;
}
Now in the Orange class or any other class that needs to use Orange. The
following code: Orange.COLOR returns 0.
Code:
import mypackage.Orange;
class Table {
public function Table() {
trace("Orange.COLOR: " + Orange.COLOR); // outputs 0
}
}
Things change when this code is applied to the timeline:
Code:
Table.fla
import mypackage.Orange;
trace("Orange.COLOR: " + Orange.COLOR); // outputs undefined
trace("Orange.SEEDS: " + Orange.SEEDS); // outputs 0
Tracing Orange.COLOR gives me undefined. But if I import mypackage.Fruit.
Fruit.COLOR traces out 0.
Code:
Table.fla
import mypackage.Fruit;
trace("Fruit.COLOR: " + Fruit.COLOR); // outputs 0
Can someone shed some light on why in an FLA that the subclass (in this
case Orange) cannot access its super class static variables
(Orange.COLOR)?
Mc's That Subclass MovieClip Initialisation Delay
Hi,
A have an mc in my library("child_mc") that subclasses MovieClip. If I attach it to the stage at runtime, there are no problems accessing it's public properties.
In my library I also have an mc with a linkage ID "parent_mc". It does NOT subclass MovieClip, but does contain an instance of "child_mc".
If I attach parent_mc to the stage at runtime and immediately try to access the properties of "child_mc" it contains, I can't. The clip itself traces as existing, but and properties trace as undefined.
The only way round this is to set an interval of 1/100th of a second before I try and access it. Then I can access it fine.
Has anyone got a way round this? Am I doing something wrong?
Linkage Wont Take Subclass As Valid
What I'm trying to do is to have 2 movieclips in the library called Info1 and Info2. Info2 extends Info1.
Info1:bare bones of title, main text, and scrollbar
Info2:extends Info1
adds a picture and links
The problem is in the library, I can't set the linkage to Info2 because I get complier errors saying my instances are undefined. Therefore I have to link to Info1. However, each linkage needs to be a unique identifier, therefore Info1 can't link to Info1.
If that makes sense, can you see my problem and a way to fix it, while maintain the structure I have (or at least a good one)? I could just copy and paste all of Info1 into Info2, but that doesn't seem like very good OO to me.
p.s. I've tried doing what Senocular said here however, it wont let me add superclasses as a base class and have a class path for the linkage ID.
Calling A Movieclip On Stage From A Subclass?
Is it possible to reference a predetermined movieclip object on the stage from a function within a subclass?
I have a document class which is then calling a subclass and within the subclass I have a function that I would like to change the properties of a movieclip on the stage.
can this be done?
Access Displaylist Item From Subclass
If i have a Doc Class that loads a Movieclip to the stage, how would i write a subclass that was able to remove it:
ActionScript Code:
//Doc Class
package {
import flash.display.*;
public class ExampleA extends MovieClip {
var myShape:Shape = new Shape();
var myContainer:MovieClip = new MovieClip();
public function ExampleA():void {
var callB:ExampleB = new ExampleB();
stage.addChild( myContainer );
myShape.graphics.beginFill(0xFF0000);
myShape.graphics.drawRect(0, 0 , 200, 100);
myShape.graphics.endFill();
myContainer.addChild( myShape );
trace(stage.numChildren);
}
}
}
And i want to remove myContainer from within the subClass ExampleB
Change Subclass URLRequest From MainClass
Can somebody tell how I would go about changing a subclass URLRequest from the mainClass or what I'm doing wrong here? Thanks.
package sdClasses {
import flash.display.Sprite;
import flash.net.URLRequest;
public class Image extends Sprite {
private var _file:URLRequest;
public function get changeImage():URLRequest {
return _file;
}
public function set changeImage(url:String):void {
_file = URLRequest(url);
}
public function Image(url:String) {
_file = new URLRequest(url);
}
public function getImageUrl():URLRequest {
return _file;
}
}
}
[AS3] Subclass Method Return Type
I am extending the Array class. Many of its methods return Array objects, but I would like them to return instances of my subclass. I only need to change the return type (and the argument if it is also of the Array class), as the method does just what I want it to otherwise.
Overriding the method won't work, as the return type has to be the same. Attempting to use a method that returns an Array to assign the value of a subclass of Array generates an error, how can I fix this? (Or is more detail needed?)
Calling A Subclass Method From A Superclass
Let's use the following example to illustraite my dillema:
Code:
package {
public class Superclass
{
public var $thisVar:String = undefined;
function Superclass(){
$thisVar = 'woot';
}
}
}
package {
public class Subclass extends Superclass
{
function Subclass(){
trace($thisVar);
}
}
}
Given the above example, the following code when used inside the Superclass would cause a Stack Overflow:
Code:
subclass:Subclass = new Subclass();
Because of this, I can't really use any of the subclass methods.
Since I'm somewhat new to proper OOP practices, I'm also wondering whether or not this is a good idea. The current goal of the relationship between these two classes is:
* extending the subclass should allow me to use $variables defined in the superclass on subclass methods.
* by instantiating the subclass i can call some of the subclass functions from inside my superclass
Since I could probably set this up in a more efficient manner, any OOP advice here would be appreciated.
Class Design - Subclass Error
In the .fla I have four buttons.
>instances pop_btn, pop2_btn, pop3_btn and pop4_btn.
.fla code:
Code:
import PopUp;
pop_btn.addEventListener(MouseEvent.MOUSE_DOWN,openPopUp);
var film_mc:MovieClip;
var pop:PopUp;
I have created a class "PopUp.as"
.as code:
Code:
package PopUp{
import flash.display.MovieClip;
public class PopUp {
function openPopUp(evt:MouseEvent):void
{
createFilm();
attachPopUp();
}
function createFilm():void
{
film_mc=new MovieClip();
film_mc.graphics.beginFill(0x000000,1);
film_mc.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
film_mc.alpha=0.5;
addChild(film_mc);
}
function attachPopUp():void
{
pop=new PopUp();
pop.x=stage.stageWidth/2-pop.width/2;
pop.y=stage.stageHeight/2-pop.height/2;
addChild(pop);
pop.close_mc.mouseChildren=false;
pop.close_mc.buttonMode=true;
pop.close_mc.addEventListener(MouseEvent.MOUSE_DOWN,closePopUp);
}
function closePopUp(evt:MouseEvent):void
{
removeChild(pop);
pop=null;
removeChild(film_mc);
film_mc=null;
}
}
}
When run I am receiving an error stating that the PopUp class must subclass flash.display.MovieClip as well as it telling me that the function openPopUp is not a compile-time constant.
What am I overlooking?
UIComponent Subclass / GetDisplayObjectInstance Method
I'm developing a component that subclasses UIComponent. I am using the getDisplayObjectInstance method to create the display objects used in the draw method.
The component is used in a SWF that is loaded into a child app domain of another SWF.
The component does not exist in the main SWF. Thus, I expected the component class to reside in the child app domain and have access to the classes in the loaded SWF. Instead, the component is looking in the application domain for the skins and not finding them.
Is my logic wrong? Why does the component's loaderInfo point to the main SWF? What is the best approach without copying the assets into main SWF's library?
|