Actionscript 2 Class Extending Movieclip
Hi everyone
I have a question which I hope someone will be able to help with.
I have a class which is the base for a movieclip in my libary (the movieclips will make up the navibar buttons) and this class extends movieclip. At first I had a load of functions inside this class and it worked fine, the class drew a rotaing 3d cube.
I then wanted to take it one step further because I need 2 cubes per movieclip, so I took out all the functions for drawing the cube and put them into their own sperate class which extends movieclip (this cube class needs to actually do the rendering out onto the screen), then in the movieclip base class I would create 2 instances of the new cube class, and call the necessary functions in cube to draw it out onto the movieclip, only it doesn't!
is it what I am trying to do possible? here is some basic code of what I'm trying to achieve.
class menButton extends MovieClip{
public var liney:drawLine
public function menButton(){ liney = new drawLine(); }
}
class drawLine extends MovieClip{
public function drawLine(){ this.clear(); this.moveTo(100,100); this.lineStyle(2,0,100); this.lineTo(100,100); } }
I hope I made it understandable, any help would be greatly appreciated. Thanks in advance Dan
FlashKit > Flash Help > Flash ActionScript
Posted on: 11-25-2003, 06:43 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Extending MovieClip Class
Hi ppl,
For the sake of understanding developing custom componnets in flash MX, I am developing a component which has a method which pops up a trace box displaying the _width property of a movieclip whose name is passsed as an argument to the method.
Here is the code:
PHP Code:
#initclip
function widthClass(mcp) {
getWidth(mcp);
}
MovieClip.prototype.getWidth = function(m) {
trace("The width is "+m._width);
};
Object.regiterClass("gWidth", widthClass);
#endinitclip
I tried coding the component using the following code as well.
PHP Code:
#initclip
function widthClass(mcp) {
getWidth(mcp);
}
widthClass.prototype=new MovieClip();
widthClass.prototype.getWidth=function(m){
trace("The width is "+m._width);
};
Object.regiterClass("gWidth", widthClass);
#endinitclip
This code didnt work, so whats the difference between
PHP Code:
MovieClip.prototype.getWidth = function(m) {
trace("The width is "+m._width);
};
and
PHP Code:
widthClass.prototype.getWidth=function(m){
trace("The width is "+m._width);
};
Arent the two approaches extending the movieclip class to a new class known as widthClass, well since the two approaches (rather methods of the class)are having a different effect, I guess there is some
difference in the principles of using these two, can anyone guide me on this?
Also I saw that I can accomplish the same simply by this code for the component.
PHP Code:
MovieClip.prototype.getWidth=function(mcp){
trace("The width is "+mcp._width);
}
Now I didnt used the pragmas #initclip and #endinitclip also I didnt create a new class, or did I? can anyone pl tell me how did this work? Am I creating a class by the name getWidth here, or writing a
method to the general movieclip class?
Am I missing something very basic and important, pl pardon me if I have asked something really stupid. I want to clear many issues on using classes in Flash for the sake of component development.
Thx
Extending Movieclip Class - AS2
Can Someone show me how to use this class. I am new to extending movieclip class.
Download actionscript file: http://0-style.com/ScrambleText.as.zip
Extending MovieClip Class
I am having a confusing issue and I think it is my lack of understanding how sub-classing works. I want to extend the MovieClip class and still be able to use my new class like I would use the MovieClip class for methods I have not over-ridden - like the onPress and onRelease handlers. But, the onPress handlers do nothing...an example follows:
A basic class in the NewClass.as file:
class NewClass extends MovieClip {
private var myMC:MovieClip;
private var _sVar1:String;
private var _sVar2:String;
// Constructor
public function NewClass(var1:String, var2:String, __parent:MovieClip) {
_sVar1 = var1;
_sVar2 = var2;
myMC = new MovieClip();
myMC = __parent.createEmptyMovieClip("_myMC", 10);
drawMyMC();}
public function get Var1():String {
return _sVar1;}
public function get Var2():String {
return _sVar2;}
private function drawMyMC():Void {
myMC.beginFill(0x0066FF, 100);
myMC.moveTo(100, 100);
myMC.moveTo(100, 100);
myMC.lineTo(200, 100);
myMC.lineTo(200, 200);
myMC.lineTo(100, 200);
myMC.lineTo(100, 100);
myMC.endFill();}}
Used as follows in a .fla file:
import NewClass.as
var myObject:NewClass = new NewClass("stuff", "moreStuff", _root);
myObject.onPress = function() {
trace(this.Var1);
//do stuff here}
The onPress handler does nothing...any ideas on why?
Thanks a whole heck-of-alot in advance.
jON bEEBE
Extending The Movieclip Class
I have successfuly extended my movieclip class to add a few properties of my own.
Code:
dynamic class ThumbnailMC extends MovieClip {
public var tnWidth:Number;
public var tnHeight:Number;
public var lrgWidth:Number;
public var lrgHeight:Number;
public var caption:String;
public var lrgImage:String;
public var thumbnail:String;
}
However, I use movieClipLoader to load jpgs into these thumbnails dynamically. That works... but when I receive the movieClipLoader events (onInitLoad, etc) I can only access the parameters of the movieClip and not my parameters.
Code:
mcl.onLoadInit = function (targetMC) {
trace(targetMC._x); //Returns _x
trace(targetMC.tnHeight); //Returns undefined
}
Note that I can access my properties from anywhere else... just not from the reference targetMC that is passed to the onLoadInit event.
Any suggestions?
Thanks!
Extending MovieClip Class?
Hi, I'm pretty new to this and appreciate any help getting me up to speed... I have some movie clips and want to add some methods and properties to them rather than having to pass them on as arguments to global functions. For example on each of the movie clips I want the functionality of them moving using the new Tween class when they are clicked by the mouse. I know the basics of creating a class with the properties and methods i want the clips to have, but how do i 'tie' the existing movie clips in so they have these methods (i.e. so I can write:
onPress = this.moveLeft(400);
onRollOver = peepRight(20);
etc.
Hope this makes sense, thanks, Sean.
Extending The MovieClip Class
I want to have a class create a movie clip from an instance in the library and create more propterties. For some reason the movie clip doesn't show up when it is created...I'm doing something like this passing the instance name, var playButton:myButtonClass new myButtonClass("playButton");
The class looks something like this...
class myButtonClass extends MovieClip {
static buttonID:Number = 0;
var thisButtonID:Number;
var buttonMovieClip:MovieClip;
function myButtonClass (instance){
buttonID++;
buttonMovieClip = attachMovie(instance, "new instance", 1);
thisButtonID = buttonID;
}
}
If I use attachMovie outside the class it works great but I want encapulate it in one place (adding lots more properites). This must be some type of scope issue? I'm clueless.
T
Why Is Extending MovieClip Class Different?
I've been going through an OOP AS 2.0 tutorial , and I was curious WHY this code (a public function) is in a class which extends the MovieClip class and is used to affect a linkage item in the library:
Code:
// init method for arguments which in other normal
// circumstances (non-MovieClip classes) would be
// given to the constructor. Not an option with MovieClips
function init (pGravity:Number, pBoundries:Object) {
gravity = pGravity;
boundries = pBoundries;
return this;
}
Is there something undocumented about why I wouldn't pass those parameters in when instantiating a new instance of the class in question? What is different about extending the MovieClip class?
Thanks,
IronChefMorimoto
Extending The Movieclip Class
hi.
i'd like to create a class called 'AdvancedButton' which will extend the MovieClip Class.
the purpose of doing so is to eventually being able to define special methods like "stance" which will handle the movieclip in case of rollout rollover ect'...
this is what i wrote in the AdvancedButton.as file:
Code:
class AdvancedButton extends MovieClip{
public function set Stance(sMode:String){
switch (sMode){
case "over":
this.gotoAndStop(2);
break;
case "out":
this.gotoAndStop(1);
}
}
}
in the *.fla i've created i create a new movieclip called 'mcButton' in which i set 2 frames - frame 1 for the rollout stance and frame 2 for the over stance.
on the first frame of the movie i wrote:
Code:
mcButton = new AdvancedButton();
mcButton.onRollOver = function(){
this.Stance("over");
}
mcButton.onRollOver = function(){
this.Stance("out");
}
now, the problem is that flash doesnt recognize the 'mcButton' as a movieclip and therefore doesnt trigger the onRollOver and onRollOut. and this in spite of declaring the AdvancedButton class to extend the movieClip class.
how do i make flash understand that 'AdvancedButton' inherits all MovieClip's properties, event handlers and methods?
thanks upfront.
Why Is Extending MovieClip Class Different?
I've been going through the OOP AS 2.0 tutorial here on Kirupa, and I was curious WHY this code is in a class which extends the MovieClip class and is used to affect a linkage item in the library:
Code:
// init method for arguments which in other normal
// circumstances (non-MovieClip classes) would be
// given to the constructor. Not an option with MovieClips
function init (pGravity:Number, pBoundries:Object) {
gravity = pGravity;
boundries = pBoundries;
return this;
}
Is there something undocumented about why I wouldn't pass those parameters in when instantiating a new instance of the class in question? What is different about extending the MovieClip class?
Thanks,
IronChefMorimoto
Extending The MovieClip Class
Hi guys,
I am wondering how I can add additional methods to the MovieClip class so that every MovieClip I create will have access to those methods automatically. What I mean is doing something like declaring a function "MovieClip.prototype.functionName = function()....." in ActionScript 2.0, but doing so in ActionScript 3.0 instead.
I understand that I can create a new class that extends the MovieClip class by doing "public class ClassName extends MovieClip" and write my own methods under it, but then I will need all my MovieClip symbols to implement this new class I created in order to access the methods I made. How can I achieve the effect in which I will be able to access my own methods by just having the symbol implement the MovieClip class instead of implementing a new class which extends the MovieClip class?
Extending The MovieClip Class
I've got a class with a constuctor as below. It creates an alien invader and attaches a invader picture movieclip from the library to it.
ActionScript Code:
class Invader extends MovieClip {
private var invaderContainer_mc:MovieClip;
public function Invader(target:MovieClip, depth:Number {
invaderContainer_mc = target.createEmptyMovieClip("invaderContainer", depth);
bringInvaderPic();
}
private function bringInvaderPic():Void {
invaderContainer_mc.attachMovie("invader", "invader", 1);
}
}
I want to use MovieClip methods like _rotation etc on my freshly created invader in I guess something like the manner below
ActionScript Code:
invader1= new Invader(this,5);
//then use MovieClip method like
invader1._rotation=45;
How do I do this?
[as2] Extending Movieclip Class
hi,
I'm having problems with this:
ActionScript Code:
class Foo extends MovieClip {
public var mc;
public function Foo () {
createEmptyMovieClip("mc", 100);
}
}
var f1:Foo = new Foo();
trace(f1.mc instanceof MovieClip);//false
There's seems no solution... Also:
ActionScript Code:
var mc=f1.createEmptyMovieClip("hi",200);
trace(mc);//undefined
help...
Getting A MovieClip Into A Custom Class Extending MovieClip
I have class that extends movie clip, but I can't seem to find a way to turn an existing movie clip into the class.
Here's the class:
Code:
package
{
import flash.display.Stage;
import flash.display.MovieClip;
public class Character extends MovieClip
{
private var stageReference:Stage;
private var characterMovieClip:MovieClip;
public function Character(inputStageReference:Stage, inputMovieClip:MovieClip):void
{
stageReference = inputStageReference;
characterMovieClip = inputMovieClip;
this = characterMovieClip;
trace("character instantiated");
}
}
}
The "this = characterMovieClip;" obviously creates a problem, but how else could I do this?
I've tried casting an existing MovieClip to the Class, which also doesn't work.
Thanks!
Slider AS2 - Extending Movieclip Class
I am trying to sync a slider with moiveclip. The movieclip is going to contain images that you can click on. I am using AS2 by extending the movie clip class.
Code:
class Drag extends MovieClip {
function Drag() {
onPress = doDrag;
//onRelease = doDrop;
onReleaseOutside = doDrop;
}
private function doDrag():Void{
startDrag(sliderShell_mc.req_mc, true, 0, 0, 550, 0)
}
private function doDrop():Void{
stopDrag();
}
}
Extending MovieClip Class & Constructors
I'm having a problem understanding a piece of code from a program written by Joel Bircher on kirupa.com.
Basically, he extends the MovieClip class with the Snowflake class shown here (I've removed the other methods since they aren't relevant to my question):
Code:
class Snowflake extends MovieClip {
private var i:Number;
private var k:Number;
private var rad:Number;
private var w:Number;
private var h:Number;
private var parent:MovieClip;
public function init(parent):Void {
this.parent=parent;
this.w=parent.width;
this.h=parent.height;
this._xscale = this._yscale=20+Math.random()*100;
this._x = -w+Math.random()*(3*w);
this._y = -10+Math.random()*h;
i = 1+Math.random()*2;
k = -Math.PI+Math.random()*Math.PI;
rad = 0;
}
}
He then creates several instances of the Snowflake class from the Snow class here:
Code:
class Snow {
private var n:Number; // number of flakes
private var flakes:Array; // array of flakes
private var mc:MovieClip; // the clip in which to make the snow
private var width:Number;
private var height:Number;
private var wind:Number;
public function Snow(n, mc,width, height,wind) {
this.n=n;
if (mc == undefined) {mc=_root;}
this.mc=mc;
this.width=width;
this.height=height;
this.wind=wind;
flakes=new Array();
for (var i=0; i<n;i++) {
flakes[i]=Snowflake(mc.attachMovie("*snowflake","flake"+i,i));
flakes[i].init(this);
}
}
Where *snowflake is a symbol in the library
What I don't understand is this line:
Code:
flakes[i]=Snowflake(mc.attachMovie("*snowflake","flake"+i,i));
Obviously, the Snowflake class doesn't have a constructor defined as seen above. I'm not even sure if it can have a constructor since it extends the MovieClip class, which doesn't have a constructor. However, this looks to me like he's created a new instance of the class, but without the new keyword. And how is he passing the MovieClip to the Snowflake "constructor"? I know some of these questions may not even make sense, but I'm thoroughly confused on this point.
I've attached a zip file containing the .fla and two .as files for those who want to view the whole program.
Question On Extending MovieClip Class
Hi I've written a class called FadeControls.as that extends the MovieClip class. In the FLA I'm testing with I have movieclip symbols in the library that I can assign the AS 2.0 Class linkage property to read the FadeControls class and apply to that one symbol.
My question is...is there a way to import that class and have it apply to ALL movieClip instances without having to assign AS 2.0 Class links for every MC in the library? The only way I've been able to get the class working is by choosing the AS 2.0 Class for every MC in the library that uses the class....which would be quite a pain for large projects and I'd rather use prototypes in lieu of that. Anyone know how to do this??
Class Extending MovieClip Question, Some Help Please
Hi,
I'm wondering if there is a way of extending a class which is extending the movieClip class?
Or generally a way to add extra methods to an allready existing class without having to add them in the actuall class declaration.
I was thinking of using Interfaces but how can I implement an Interface to a class which is extending a movieclip?
as far as I know I have to write something like this:
Code:
import interfaceName
class className implements interfaceName{
//stuff
}
but where do I put the code which extends the MovieClip?
Code:
class className extends MovieClip{
//
}
Cheers,
Manorius
How To Create An Instance Of Class Extending MovieClip In AS2.0?
In Action Script 2.0, how do you create an instance of a class that extends the MovieClip class and put it on the screen?
So I have a class below that extends MovieClip that simply draws a triangle. How do programmatically create an instance and put it on screen? I tried createClassObject() but that didn't work.
class MyMovieClipClass extends MovieClip
{
// Constructor
function MyMovieClipClass()
{
this.drawMe();
}
// Draw a simple triangle for the heck of it.
private function drawMe():Void
{
this.clear();
this.lineStyle(10, 0xCCCCCC);
this.lineTo(300,0);
this.lineTo(300,200);
this.lineTo(0,0);
}
}
Extending Class That Has Extended MovieClip Error
I have a generalized button class for a new site I'm creating. This class holds all the more general methods for the buttons, including the over, press, and out events. I am currently trying to extend this class for each button since each button will be it's own specific movieclip in the library. Now each of these movieclips have movieclips inside of them such as "over_mc". The base class often references this movieclip to, for instance, play it. But, when I extend the base class, I get the following error (IllPill.as is my base class and AboutIllPill.as is the class that extends it):
AboutIllPill.as, Line 1 1152: A conflict exists with inherited definition IllPill.over_mc in namespace public.
[F8] AS 2.0 Passing Parameters To Class Constructors Extending MovieClip
Hi, I read that you need to create an init function to pass parameters to a class that extends the MovieClip class and that you cant't pass parameters in the constructor itself.
But I played around with it, modyfying such a class:
class Mover extends MovieClip {
function Mover(num1, num2) {
trace(num1*num2);
}
}
and it works fine. parameters passed and processed and it extends the MovieClip class. So what am I missing?
Extending The Movieclip Class And Handling Events In The Nested Movieclips.
I am creating a slider component. I have created a movieclip and a custom class that extends MovieClip to implement the slider. The code for the custom class is as follows:
ActionScript Code:
import mx.events.EventDispatcher;
class Slider extends MovieClip
{
// Controls
private var pointer:MovieClip;
// Variables
var m_isDragging:Boolean = false;
var m_maximum:Number = 100;
var m_minimum:Number = 0;
// Event functions
var addEventListener:Function;
var dispatchEvent:Function;
var removeEventListener:Function;
public function Slider()
{
// Set-up event handling
EventDispatcher.initialize(this);
var thisObject:Slider = this;
pointer.onMouseDown = function():Void
{
// Let the user start dragging
this.startDrag(true, 0, 3, 100, 0);
// Flag that the user is dragging
m_isDragging = true;
};
pointer.onMouseUp = function():Void
{
// The user has stopped dragging
this.stopDrag();
// Flag that the user is no longer dragging
m_isDragging = false;
}
pointer.onMouseMove = function():Void
{
if (m_isDragging)
{
// Set-up the object for handling the event
var eventObject:Object = {target:thisObject, type:'valuechanged'};
eventObject.value = thisObject.value;
// Now run the event
thisObject.dispatchEvent(eventObject);
}
}
}
public function get maximum():Number
{
return m_maximum;
}
public function set maximum(value:Number):Void
{
m_maximum = value;
}
public function get minimum():Number
{
return m_minimum;
}
public function set minimum(value:Number):Void
{
m_minimum = value;
}
public function get value():Number
{
// Work out the amount
var size:Number = m_maximum - m_minimum;
return size * pointer._x / 100 + m_minimum;
}
}
The nested movieclip "pointer" is the pointer for the slider.
Everything works correctly when there is a single instance of my slider on the stage. However, when I add a second instance, only the first instance works correctly - the event handling for the onmousedown event of the second instance seems to be handled by the first instance I added. I have attached a swf file showing the problem.
Extending A Class That Is A Document Class Of A Swf/fla
Hey
I have a question about extending or subclassing classes in as3 and flash.
I have a fla project that has its Document Class set to an as3 class called Portrait. B/c the portrait class is a document class of my fla project, it directly accesses all movieclip objects in the scene.
I want to create a new project that extends this project. By that, I mean I would like to extend the functionality by adding more movieclip objects to the scene and more script, but keep the original source code. Is this even possible?
I tried writting a new class called PortraitExt which extends the Portrait class. And I duplicated the original project, added some new objects, and set its document class to PortraitExt. However, when I tried compiling, it complained about the orignal Portrait class not being able to find the movieclip objects that are contained in the scene.
Thanks!
Accessing Predefined MovieClip From Actionscript 2.0 Class
Hello, noob's passing by. I'm not sure whether anyone has asked this question before, but I'll clearly describe my problem here so I hope you guys can give me some tips on how I can solve it.
Firstly, I have 3 MovieClip symbols in the Library Panel : World, Bank, and Hospital. In the World MovieClip, I drag Bank and Hospital MovieClip into it. So, this means that there are a Bank and a Hospital in the World MovieClip. I give instance name 'bank_mc' and 'hospital_mc' for Bank and Hospital respectively. Then, I link the World MovieClip with a AS 2 class named 'World' by adding 'World' into the AS 2.0 class text field in the linkage property.
Now I create the 'World' class in World.as file. My question is, how can I access 'bank_mc' and 'hospital_mc' from my World class, let say I want to change the _x and _y properties of 'bank_mc' and 'hospital_mc'? The reason is that compiler complained about not having such instance when I have codes like 'bank_mc._x = a_number;' in the World class.
I hope that someone can help me with this as soon as possible because I'm creating a game for my final year project.
Thanks in advance.
ActionScript 2.0 - MovieClip Events As Class Functions
Hi
I was wondering if you code help me out with Actionscript 2.0 and classes.
I have built a movie which has some nested movies within. I have created a class called ButtonMc in a .as file and used linkage to connect the symbol in the .FLA file with the class code in the ButtonMc.as file . This is the code for ButtonMc class:
Code:
class ButtonMc extends MovieClip
{
//stores the MovieClip Instance which will be assigned to this class
private var mcButton:MovieClip;
/* Constructor - takes in the movieclip*/
public function ButtonMc(mcInstance:MovieClip, mcInstanceName:String, mcInstanceDepth:Number, xPos:Number, yPos:Number)
{
//mcInstance will hold value "this"- which will mean a connectionwill be made
//between this objects (when created) movieclip property and the symbol in the .fla.
mcButton = mcInstance.attachMovie("ButtonMc", mcInstanceName, mcInstanceDepth);
//set the initial position of movie on stage
setPosition(xPos, yPos);
//dont display the handcursor for this movie clip
mcButton.useHandCursor = false;
//starts the onrollover event
}
/* Sets/Changes the position of the movie clip on stage*/
public function setPosition(x:Number, y:Number)
{
mcButton._x = x;
mcButton._y = y;
}
/* when mouse rolls over */
public function onRollOver()
{
mcButton.gotoAndPlay("over");
}
}
Then on my _root(main timeline) i have a action to create an instance of the the class and display the movie. I have this action:
Code:
var mc:ButtonMc = new ButtonMc(this, "mcunderstand", 0, 10, 50);
This movieclip displays when run, but nothing happens when i rollover the movieclip, it does not work and does not go to and play the specified frame for the "over" state.
Am i doing this wrong? I thought that all code related to an object would go inside the class and be ready to use?
Any help on this would be great
Thanks alot.
Extending The XML Class?
I've been playing around with a class that extends the XML object.
I've tried it like this, but there are compiles issues:
import classes.GenericXml;
var test:XML = new XML();
test.GenericXml("xml/photoAlbum.xml",null,"PhotoAlbum");
//or
var test_:GenericXml = new GenericXml();
test_.GenericXml("xml/photoAlbum.xml",null,"PhotoAlbum");
I've never extended an xml class before so was hoping someone can offer some pointers?
Maybe the classpath is incorrect?
Here are the files if anyone wants to look.
Extending Mc Class
Hello all,
I am not really quite sure how to describe this but basically i have a NavigationButton class that extends the MovieClip class giving rollOver, rollout, onPress, etc... functionality.
I am having a heck of a time passing the variables from the class constructor into the functions. they are tracing undefined. I have tried to set a scoper but still to no avail.
any help in understanding this would be greatly appreciated.
thanks,
Derek
Code:
import com.mosesSupposes.fuse.*;
class com.JDV.utils.NavigationButton extends MovieClip{
var ref:Object;
var lnk:String;
var s:Object;
function NavigationButton(sc, _ar){
s = this; //traces correct
}
function init(sc, _ar) {
ref = sc //traces correct
lnk = _ar[0].url //traces correct
}
function onRollOver():Void{
trace(lnk) // traces undefined
trace(s.lnk) //traces undefined
}
function onRollOut():Void{
}
function onReleaseOutside():Void{
}
function onPress():Void{
}
function onRelease():Void{
}
}
Help Extending Class
Ok so I made this base class that extends MovieClip and works fine. The problem occurs when I try to call a function from a class that extends the base class I made. The base class is called "RCACGame" and the class I am trying to extend RCACGame with is called "JobsClass"
ActionScript Code:
import JobsClass;
public class RCACGame extends MovieClip
ActionScript Code:
public class JobsClass extends RCACGame
In the "JobsClass" class I have a function called job1:
ActionScript Code:
public function job1():void
and I am trying to call it in my base class "RCACGame" like this:
ActionScript Code:
JobsClass.job1();
but I keep getting this error. 1061: Call to a possibly undefined method job1 through a reference with static type Class.
Can't figure out how to get it to work. Any help would be appreciated.
Class Extending MC, PLEASE GOD HELP
PHP Code:
package {
import flash.display.MovieClip;
import flash.events.Event;
public class DumbClass extends MovieClip {
var dumbXS:Number = 0;
var dumbYS:Number = 0;
var dumbACC:Number = 0.6;
var dumbDEC:Number = 0.92;
public function DumbClass() {
this.addEventListener(Event.ENTER_FRAME, DumbMove);
}
public function DumbMove(evt:Event):void {
//Increases Speed
this.x += dumbXS;
this.y += dumbYS;
//Reference to a MovieClip on stage called "user".
if (user.y < this.y) {
dumbYS -= dumbACC;
}
//Reference to a MovieClip on stage called "user".
if (user.y > this.y) {
dumbYS += dumbACC;
}
//Reference to a MovieClip on stage called "user".
if (user.x < this.x) {
dumbXS -= dumbACC;
}
//Reference to a MovieClip on stage called "user".
if (user.x > this.x) {
dumbXS += dumbACC;
}
///Decrease Speed
dumbYS *= dumbDEC;
dumbXS *= dumbDEC;
}
}
}
I'm trying to get the Movieclip "user"s .x/y position from inside this class which is associtaed with an MC in the library which is spawned by this function several times:
PHP Code:
function spawnCircle() {
var screen_side:Number = Math.round(Math.random()* 3);
var DumbTarget:DumbClass = new DumbClass();
//this["dumbTarget" + dumbLoop] = dumbTemp;
addChild(DumbTarget);
if (screen_side == 0) {
DumbTarget.x = -15;
DumbTarget.y = -15;
}
if (screen_side == 1) {
DumbTarget.x = 815;
DumbTarget.y = -15;
}
if (screen_side == 2) {
DumbTarget.x = 815;
DumbTarget.y = 615;
}
if (screen_side == 3) {
DumbTarget.x = -15;
DumbTarget.y = 615;
}
}
I get an error that "user" is an undefined property even though its on the stage any ideas how I can fix this? I've been told that I need to get the user .x/y through a constructor but I have no idea how to do this and I am relatively new to AS3.
Extending XML Class In AS 2.0
I'm trying to extend the XML Class in AS 2.0..
My class looks following:
class XMLComm extends XML {
function getNamedNode(nodeToFind:String) {
//var chNodes = childNodes;
for (var x in childNodes) {
if (childNodes[x].nodeName == nodeToFind) {
return childNodes[x];
}
}
return "No node named "+nodeToFind;
}
}
In the good AS 1.0 days one could do the following:
XMLNode.prototype.getNamedNode = function(nodeToFind) {
var x;
var chNodes = this.childNodes;
for (x in chNodes) {
if (chNodes[x].nodeName == nodeToFind) {
return chNodes[x];
}
}
return "No node named "+nodeToFind;
};
trace (myXMLData.firstChild.getNamedNode("Properties").getNamedNode("Test")) etc.
How do i achieve it similar in AS 2.0?
Or is there another way of doing things?!
Kindly regards
//netPhreak
Extending A Movieclip And Calling A Nested Movieclip
Hi, I'm trying to do somthing like this:
class Timer extends MovieClip
{
// constructor
function Timer()
{
this.onEnterFrame = CountDown;
}
// CountDown
function CountDown ()
{
this.mask_mc._yscale--;
}
}
And it won't let me (There is no property with the name 'mask_mc'.)...
Alternatively, I try to do this:
class Timer
{
var __timer_mc:MovieClip;
// constructor
function Timer(timer_mc)
{
__timer_mc = timer_mc;
this.__timer_mc.onEnterFrame = CountDown;
}
// CountDown
function CountDown ()
{
this.mask_mc._yscale--;
}
}
And it won't work either...
So my question is:
How can I call a nested MovieClip from inside an onEnterFrame method (which is declared in a class that extends a MovieClip)?
Thnx,
EZ
Extending Xml Class There Is No Method With The Name ...
hey guys... got a question for more of an advanced user... i have a class that extends xml class and i added another simple function there... testme() which just traces a helloworld msg , but when i call it from another class (after i created the object ofcourse) says there is no method with that name... can anyone help? ---> http://pastebin.neod.com/?id=1560
Extending Array Class
I'm trying to extend the Array class...
ex.
my_array = new cArray("bob", "cat", "dog");
how do I get the variables passed, onto the actual array?
I tried...
Code:
dynamic class cUtil.cArray extends Array{
//CONSTRUCTOR:
//====================================================================
function cArray(){
super(arguments);
}
}
my_array = new cArray("bob", "cat", "dog");
trace(my_array.length); // outputs "1"
it should output "3"???????
Extending The Texfield Class
I currently working on a userinterface that dosen't have have clicking. It's becoming quite the challenge...
Anyways, I don't know if what I'm asking is possible, but is there a way to extend the Texfield class to have a onRollOver event?
Extending Rollover Class
Hi guys, I have got an Mouse_Over event class that I want to extend because I would like to pass some variables on, but I am not having any luck. The swf runs without any errors, but it seems like my function is not being fired when I rollover the relevant button?
Any help with this would really be appreciated as I am getting quite frustrated, and I really don't want to resort to a hard coded solution to the problem, because extending the event class is far more elegant and flexible.
My Flash File Code:
PHP Code:
var RollOver:MouseOverEvent=new MouseOverEvent(MouseEvent.MOUSE_OVER,dynheadingname, dynsubheadingname);
dispatchEvent(RollOver);
this.features_holder_mc.addChild(buttonhit).name = dynbuttonname;
this.features_holder_mc.getChildByName(dynbuttonname).addEventListener(MouseOverEvent.MOUSE_OVER, mouseover_subfeature);
My Actionscript Class:
PHP Code:
package com {
import flash.events.Event;
public class MouseOverEvent extends Event {
public static const MOUSE_OVER:String = "MOUSE_OVER";
public var dynheadingname:String = "heading_i";
public var dynsubheadingname:String = "subheading_i";
public function MouseOverEvent(type:String, dynheadingname:String, dynsubheadingname:String)
{
super(type);
this.dynheadingname = dynheadingname;
this.dynsubheadingname = dynsubheadingname;
}
public override function clone():Event
{
return new MouseOverEvent(type, dynheadingname, dynsubheadingname);
}
public override function toString():String
{
return formatToString("MouseOverEvent type="+ this.type +" dynheadingname="+ this.dynheadingname +" dynsubheadingname="+ this.dynsubheadingname +" bubbles="+ this.bubbles +" cancelable="+ this.cancelable +" deventPhase="+ this.eventPhase);
}
}
}
Extending A Class- Simple
In my head this should work- i have two classes - one that has library classes passed to it:
Code:
package
{
import flash.display.*;
public class ThisClass extends MovieClip
{
public var c:DisplayObject = null;
public function ThisClass(v:Class):void
{
c = new v();
addChild(c)
}
}
}
the next class has actual instances passed to it
Code:
package
{
import flash.display.*;
public class ThatClass extends ThisClass
{
public function ThatClass(e:DisplayObject):void
{
super(null);
c = e;
}
}
}
but, once i try it,
Code:
var tc:ThisClass = new ThisClass(Spot);
addChild(tc)
var th:ThatClass = new ThatClass(tc)
addChild(th);
i get :
TypeError: Error #1007: Instantiation attempted on a non-constructor.
at ThisClass()
at ThatClass()
at Untitled_fla::MainTimeline/frame1()
why is that...i thought the super in ThatClass would override the expected class variable.
Extending The Document Class
I've build a flash FLA project which has the class "MyGame" as its document class which all works great.
Now I want to make a slightly different version of it with a few bits of extra functionality, so I've got a new FLA, and want it to use an extended version of MyGame as its document class, let's say it's called "MySlightlyDifferentGame".
So the code for MySlightlyDifferentGame looks like this...
code:
package {
import flash.display.*;
public class MySlightlyDifferentGame extends MyGame {
public function MySlightlyDifferentGame(){
super();
// stuff here...
}
}
}
Trouble is, MyGame is now not recognising any objects on the stage of the FLA any more (they're all in the same place as they were in the original).
So for example I have a button on the first frame called "play_btn", and when myGame tries to reference it, I get:
1120: Access of undefined property play_btn.
Any ideas???
Extending The XML Object Class
I know that it is possible to create a custom class that inherits everything from the MovieClip class, but is it possible to create a custom class that will inherit everything from the XML class, such as:
function MyTestClass() {
}
MyTestClass.prototype = new XML();
Extending MouseEvent Class
Hey guys,
I'm trying to see if I can add a parameter to pass a Number Variable through AddEventListener. I'm trying to create a custom class. Here's what I have thus far.
Code:
package
{
import flash.events.MouseEvent;
public class MapMouse extends MouseEvent
{
public var _mapNum:Number;
public function MapMouse(MapNumber:_mapNum):void
{
this.addEventListener(MouseEvent.CLICK, _mapNum, mapChange);
}
}
}
This would be called using an EventListener, with an additional parameter, looking something like this.
Code:
this.mapMC.TAMUmap.mapGraphic.academic_btn.addEventListener(MouseEvent.CLICK, mapChange, _mapNum);
But I'm getting errors thrown at me when I try to run this:
1046: Type was not found or was not a compile-time constant: _mapNum.
and
5000: The class 'mapMouse' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
Any suggestions would be greatly appreciated. THANKS!!!
Extending The Document Class
I've build a flash FLA project which has the class "MyGame" as its document class which all works great.
Now I want to make a slightly different version of it with a few bits of extra functionality, so I've got a new FLA, and want it to use an extended version of MyGame as its document class, let's say it's called "MySlightlyDifferentGame".
So the code for MySlightlyDifferentGame looks like this...
ActionScript Code:
package {
import flash.display.*;
public class MySlightlyDifferentGame extends MyGame {
public function MySlightlyDifferentGame(){
super();
// stuff here...
}
}
}
Trouble is, MyGame is now not recognising any objects on the stage of the FLA any more (they're all in the same place as they were in the original).
So for example I have a button on the first frame called "play_btn", and when myGame tries to reference it, I get:
1120: Access of undefined property play_btn.
Any ideas???
Extending Class Issue
I have a question regarding extending a movie class.
I have a movie named Tree.fla. It's library has MC's named Apple, Orange, Lemons and Limes.
I have a class called Apple.as that extends MovieClip in the same directory as my Tree.fla
My Apple movie clip is set to export for actionscript and it's class name is Apple
When I write this code to attach the Apple:
import Apple;
var my_Apple:Apple = new Apple()
addChild(my_Apple)
I get this:
1046: Type was not found or was not a compile-time constant: Apple.
1180: Call to a possibly undefined method Apple.
What gives? I thought the Apple MovieClip would automatically inherit the Apple class.
Extending The RadioButton Class?
Has anyone had any luck extending a UI component's class? I tried with the RadioButton class and I'm not finding a way. I really just want to add some functions functions that will happen with every instance of my RadioButton and then create that dynamically. I've tried making a class file that extends RadioButton, but I'm not sure how to put an object created from that class on the stage. I've tried using attachMovie and linking an empty movie to that class, I've also tried the createClassObject and createObject functions, but I'm not sure I did this correct ( I read something that any object made using these functions need to be in the FLA's library, but I don't know how to do that without putting an empty clip in the library that is linked to that class, and that didn't work :L).
Nothing I've tried has worked properly or maintained the variables and functionality of the original RadioButton class.
Extending Array Class
I want to define a new method to search arrays for specific values.
I have a new class defined like this:
class Array2 extends Array{
function Array2(){
}
function myMethod(){
}
}
In my code I use this line to declare a new instance:
var myArray:Array2=new Array2(1,2,3,4,5);
If I now use use:
trace(myArray[1]);
it returns 'undefined'. What is the reason for this and is there a way round it?
If I define the myArray without any values and then use the push() method it seems to work but I need Array2 to work exactly the same as Array only with some additional methods.
Cheers for any and all help
AS 3.0: Extending Event Class
I am having trouble trying to figure out how to properly extend the Event class to add parameters to events. Here is what I have. If anyone knows how to do this properly please let me know.
Attach Code
package internalAssets{
import flash.events.Event;
public class DomainEvent extends Event{
//local variables
public static var COMPLETE:String = Event.COMPLETE;
public var domain:ApplicationDomain;
//constructor function
public function DomainEvent(type:String, domain:ApplicationDomain, bubbles:Boolean = false, cancelable:Boolean = false){
this.domain = domain;
}
}//end of class
}//end of package
Extending XMLSocket Class
I'm using Flash MX 2004. I want to write a class that extends XMLSocket and provides a little more information. For instance, I want *my* socket class to have a property that indicates whether the socket is connected or not and I want the Boolean value of 'connected' to be set when the socket's onConnect event triggers. How do I modify/capture the super class's events? Perhaps someone can recommend how I might change my class:
Attach Code
class MySocketConnection extends XMLSocket {
private var __host:String;
private var __port:Number;
private var __connected:Boolean = false;
function SocketConnection() {
super();
} // SocketConnection()
public function connect(host:String, port:Number): Boolean {
__host = host;
__port = port;
return (super.connect(host, port));
}
// i want this function to be called when the XMLSocket's onConnect event is triggered
public function myOnConnect() {
__connected = true;
}
// i want this function to be called when the XMLSocket's onClose event is triggered
public function myOnClose() {
__connected = false;
}
} // class MySocketConnection
Extending MouseEvent Class
Hey guys,
I'm trying to see if I can add a parameter to pass a Number Variable through AddEventListener. I'm trying to create a custom class. Here's what I have thus far.
This would be called using an EventListener, with an additional parameter, looking something like this.
But I'm getting errors thrown at me when I try to run this:
1046: Type was not found or was not a compile-time constant: _mapNum.
and
5000: The class 'mapMouse' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
Any suggestions would be greatly appreciated. THANKS!!!
Attach Code
//Custom Class
package
{
import flash.events.MouseEvent;
public class MapMouse extends MouseEvent
{
public var _mapNum:Number;
public function MapMouse(MapNumber:_mapNum):void
{
this.addEventListener(MouseEvent.CLICK, _mapNum, mapChange);
}
}
}
//Event Listener calling custom class
this.mapMC.TAMUmap.mapGraphic.academic_btn.addEventListener(MouseEvent.CLICK, mapChange, _mapNum);
[fmx04] Extending Xml Class
hey guys... got a question for more of an advanced user... i have a class that extends xml class and i added another simple function there... testme() which just traces a helloworld msg , but when i call it from another class (after i created the object ofcourse) says there is no method with that name... can anyone help? ---> http://pastebin.neod.com/?id=1560
Extending Button Class?
Hi all, sorry if this has been answered somewhere else (I searched) or if the answer is super easy (It's possible I'm just retarded).
I am working on an interface that will have literally hundreds of buttons, navigating back/forth/in-between dozens of sections and subsections. I love the ease of skinning/labeling the built-in button component, but my fingers are rebelling at the thought of typing(or at least copy/pasting) "on(release)/gotoandplay/lastSection=/etc".
So, I figured since I was already planning on having extensive frame labeling, I would just make the instance name of the button the same as the frame label where I wanted it to go. Then just have "gotoAndPlay(this._name)" on each Button.
My question then is thus: How do i make the following a part of the button component (or a different version of it, so I still use the default component for the couple of buttons I don't want to do this), everytime I drag one onto the stage?
Code:
on (click) {
nextSection = this._name;
lastSection = _root._currentframe;
gotoAndPlay(nextSection);
}
Thanks so much to anyone who can help me out! And if there is a super easy way of doing this, please smack me, then let me know what it is
Extending The Button Class
I have an AS file named MovieClipTLnd which I created to add a property to the MovieClip class, plus a function to trace the current value of the property I added.
I works out just fine.
But when I do the same trying to extend the Button Class, it won't work.
check the last lines of this LiveDoc, a few days ago someone posted a comment regarding this problem
http://livedocs.macromedia.com/flash/mx2004/main_7_2/00001211.html#4716791
I know there are some workarounds for this problem... like embedding the button into movieclips and assigning properties as objects, but I need to know if it's possible to Extend the Built-in Button class itself just like it can be done with the MovieClip Class.
Extending An Abstract Class
i have an abstract class called Ship(extends Sprite), Ship is extended by two other classes Falcon and TieFighter. Ship,Falcon, and TieFighter are all in a package called "Ships". Falcon class is linked up to an image in the library with base class set as flash.display.Sprite. Next I have a class called Main.as.(placed outside of the "Ships" package) Code in there looks like
var falcon:Ship = new Falcon();
falcon.x = 100;
falcon.y = 100;
addChild(falcon);
obviously this doesn't work(implicit coercion of value type Falcon to an unrelated type ships:Ship), to make this work i have to do either var falcon:* or var falcon:Falcon, how come I can't type it as a Ship since technically it extends Ship,
|