Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Referencing Class Methods.



Hi,

I am have a class which I am instantiating in the first frame of a movie.
The class has a method called statecheck which I would like to access from a movie clip symbol.
I can reference the method easily from the first frame. what is the correct way of referencing it from the movieclip?

import Tpanel

var public panel:Tpanel = new Tpanel;

panel.statecheck(this); // works

the same line of code in the movieclip symbol does not.

also

_root.panel.statecheck(this); // does not work in as3

Cheers


Matt



FlashKit > Flash Help > Actionscript 3.0
Posted on: 08-20-2008, 09:55 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Overriding Base Class Methods While Calling Original Methods
I would like to write a class that extends XMLSocket. I'd like to call my class RPCSocket. Among other things, I want to add a property which indicates that the socket is 'waiting to connect'. This would mean that the connect() method of XMLSocket has been called but the CONNECT event has not yet been dispatched. I'll therefore need to override the CONNECT and CLOSE methods of XMLSocket in my class, RPCSocket.

I haven't yet seen any reason why I can't override these methods -- they are neither constant nor static nor final and do not implement an interface method (as far as I can tell) and they are inherited.

I obviously need to call the original connect() and close() methods of the XMLSocket, however. Is this code the proper way to do this? Can anyone see any particular problem with this?

code:
package {
class RPCSocket extends XMLSocket {
public var boolWaitingToConnect:Boolean = false;

public override function connect(host:String, port:int):void {
boolWaitingToConnect = true;
super.connect(host, port);
}
public override function close(host:String, port:int):void {
boolWaitingToConnect = false;
super.close();
}
}
}

[Flash 8] Referencing Class Variables From OnEnterFrame Created Within Class
Hi,
It's been a while since my last post here, but I was hoping someone could help me with a problem I'm having. I want to reference and change a class variable from within an onEnterframe function defined within a class. I can actually do this right now, but I want to do it in a different way. Here's a code sample of what I am talking about:


Test.fla file:

Code:
var t:tester = new tester()

Working tester.as file:


Code:
class tester{
private var num:Number = 100;

function tester(){
var classObj:tester = this;
var mc:MovieClip = _root.createEmptyMovieClip("test",1);
mc.onEnterFrame = function(){
trace(classObj.num); //This traces 100 (CORRECT!!!)
}
}
}
This traces 100 to the output window, just like it should

Here is the way that I would like to do it, because I want to reuse my onEnterFrame Stuff:

Code:
class tester{
private var num:Number = 100;

function tester(){
var classObj:tester = this;
var mc:MovieClip = _root.createEmptyMovieClip("test",1);
mc.onEnterFrame = this.mcOnEnterFrame;
}

private function mcOnEnterFrame(){
trace(num) //this traces undefined (BAD!!!)
}
}

As you can see, the work around to reading the class variable in the onEnterFrame function is to create a reference to the class object, before defining that function, then using the reference you created to access the class variables.

I have tried various iterations to get the second example working, but have had no luck. Does anyone know a way to get the second method working, or am I stuck using the first method.

[F8] Referencing A Static Class Inside Another Class's Instance
I've got a movie loading into a framework.

This framework has 1 instance of the class main called main.

Inside this class, another class is used, but it is used directly, not as an instance. E.g.:
code:
import com.StaticClass;
class main {
private function UseStaticClass():void {
StaticClass.init();
}
}


From my movie, I can reference the main instance as _root.main. Can I reference StaticClass at all if there's no explicit instance created or it's not assigned to a public variable?

I can't modify main to include getter/setter methods, that's why I ask.

Thanks.

Static Class Variable Referencing Class Instance
I was given the task of writing a class that would send serial requests for xml data, the idea being that the requests could be added while previous requests were still in progress, but the class would queue them and wait for the reply of one request to come back before sending the next.

The way I did this was to create a class instance for each request, and the request itself would be stored in an instance variable, waiting to be sent. A static variable called queue (accessible to all instances) was then given a reference to the instance, and when this reference got to the top of the queue, queue would call the sendRequest() method on that instance.

The reason why I am using one instance per request is so that the replies can be retrieved via the instance, so keeping each request entirely discreet.

Everything works very nicely, but the problem is my IT manager looked at the code and told me that you cannot put a reference to a class instance in a class static variable... and for this reason he has informed my line manager that he has serious reservations about the code, and recommends that it is not incorporated it into the project. However, the code works very well on my local machine and on the testsite, and no-one has experienced any problems with it.

Can someone reassure me here... I can see absolutely nothing wrong with having a class static array hold references to each of the instantiated class instances. And the proof is in the pudding.. it works. Can anyone else see a problem here?

Class And Methods
Hello,

I'm testing several methods. Methods 1 & 2 execute as expected. But, my 3rd method "mease" does nothing. Upon starting Method 3 should send a movie clip named "clip1" gliding across the stage.

I invoked method3 the same manner as the first 2 methods.


Any help would be greatly appreciated.

iaustin


//classf
clss = function(age){//f1 classification
this.age=age;
this.mreturnv= this.mpf(); //fcall

}

//--------------------------------------------------------------
clss.prototype.mpf=function(){// f2 method1 fcalled() in clss
return this.age*6;
}
//--------------------------------------------------------------


//--------------------------------------------------------------
clss.prototype.mbirthday=function(){ // f3 method2
this.age++;
this.mreturnv= this.mpf();//fcall add value to where assign to same mfp_calcu
}
//--------------------------------------------------------------


//-------------------- fease ---------------------

clss.prototype.mease=function(){ //f4 method 3
var speed = 10;
clip1._x=400;
clip1._y=250;
a=(100-clip1._xscale)/speed;
clip1._xscale+=a;
clip1._yscale+=a;
this.mreturnv= this.mpf();
}
}

//------------------end fease ---------------------


//--- invokations ---//
ioc = new clss(6); // 1 f class or function one
trace(ioc.mreturnv); // o.p value assigned to

ioc.mbirthday(); // 2 f call value of second method
trace(ioc.mreturnv);

ioc.mease();
clip1.onEnterFrame= mease;


//new invokation v=o.pfm() call assigned value also to mreturn
//functions arew called and assigned called and assigned v=f()

Get/set Methods Class
Hi everybody,

i am building a class and need get/set methods.

I am using:


PHP Code:



private var $name:String;
//...
// rest of the class
//...
public function set __name(n:String):Void
{
   this.$name = n;
};
public function get __name():String
{
   return this.$name;
}; 




This cause me error. Debugger says that the property "$name" is not static.
I don't want it to be static, just private, i want it to be in all class instances.

You can only use get/set methods for private static member of a class ?
If not, what am i doing wrong?

thanx

OOP And Class Methods
I have an OOP problem. I'm new to OOP so it can be very easy or impossible. Either way - I don't know where to look for the answer.

I have linked a class to a number of movieclips that i have on stage. The movieclips are clickable (buttons) and I want all buttons to be changed when I click one of them. E.g i want all to be dimmed if one is clicked. My problem is that i don't know how to call all my instaces of a class from one, or if it is possible!

Do I make any sense? :)

/E

Add Methods To A Class In AS 2
hi everybody,
i would like to know if the following, for example,

MovieClip.prototype.beRed = function() {
new Color(this).setRGB(0xff0000);
};

is the right way to add methods to a class in Actionscript 2?

thanks

Add Methods To A Class In AS 2
hi everybody,
i would like to know if the following, for example,

MovieClip.prototype.beRed = function() {
new Color(this).setRGB(0xff0000);
};

is the right way to add methods to a class in Actionscript 2?

thanks

Using Methods From A Non Instanced Class?
Hi,

I have a number of classes that provide methods but never require instances themselves other than to provide the methods. For instance, I have a class called MathClass which I use to store all my various maths functions and methods, but the class does not need an instance. Currently however, to allow any other classes to access the methods of MathClass I am declaring an instance of it in each class in which I need it, such as :


ActionScript Code:
package {
    public class ClassA {
        private var mathC:MathClass = new MathClass;
        public function ClassA(){
            ....
        }
    }
}

Is there a more efficient way of accessing the services of MathClass than the way I'm doing it?

Thanks again!

AS2 Accessing Class Methods
Hi guys,

i created custom classes for a quiz flash im making...

in these custom classes i also attachMovie with class references

thus i have the following class hierarchy
quote:
Movie 1/Class 1
|- Movie 2/Class 2 (attachMovie)
|--Movie 3/Class 3(attachMovie)

now i have a scenario in that Class 3 needs to execute a function of class 2

So what i did is assign a variable to movie 3 with a reference in movie 2

thus in movie clip 2 when im attaching the movie clip 3 i have quote:var movie2.self = this; and movie3.clip = self;
now when im running the code and while i can
quote:
trace(clip) // outputs movie2
in movie 3

i cant seem to
[Qe]
clip.function(param);
heres a snippet of the code


Any idea whats happening here?







Attach Code

// Movie 3/ Class 3
function checkAnswer(no:Number) {
var pts:Number = getAnswer(no).pts;
if (no == correctAnswerObj.ansNo) {
pts = correctAnswerObj.pts;
}
trace(levelMc.pts); // outputs the variable's value successfully.
levelMc.updateLevel(pts); // levelMc is movie 2 with the class 2 function 'updateLevel'
// clearQuestion();
}

// Movie 2/ Class 2
function upateLevel(pts:Number):Void {
trace('ok: '+pts); // its not executing
var allAsked:Boolean = false;
var wrong:Boolean = false;
var passedLevel:Boolean = false;
if (pts == 0) {
questionsWrong++;
trace("wrong answer");
}
if ((allAsked=(noQuestion>askNoQuestions)) || ((allowedWrong != undefined) && (wrong=(questionsWrong>=allowedWrong)))) {
trace("level over");
if (allAsked) {
trace("all questions asked");
if (levelPts>totalPts) {
trace("proceed to next round");
passedLevel = true;
} else {
trace("you failed to pass this level");
}
}
if (wrong) {
trace("You got "+questionsWrong+" answers wrong");
trace("you failed to pass this level.");
passedLevel = false;
}
if (grades) {
var rank:String = undefined;
for (var i:Number = 0; i<grades.length; i++) {
if ((pts>=grades[i]['min']) && (pts<=grades[i]['max'])) {
rank = grades[i]['gradeName'];
break;
}
}
trace("Your points make you:- "+rank);
}
quiz.updateQuiz(pts,passedLevel);
} else {
trace("ready for next question");
getNextQuestion();
}
trace("level points: "+levelPts);
}

Methods Of Class Were Not Called...
class FAniCtrl extends MovieClip
{
//---------------------------------------------- Properties
private var mRepeats :Number;
private var mCurrentRepeat :Number;
public var mAni :Number;
public var mAniName :String;
private var my_mcl :MovieClipLoader;
private var mclListener :Object;
//---------------------------------------------- Methods

/**
* constructor method
*/
public function FAniCtrl()
{
super();
mCurrentRepeat = 0;
mRepeats = 1;
mAni = -1;
mAniName = "";
_visible = false;
this.stop();
////////////////////////////////
///what is wrong with following code section: OnFrameEntry and OnLoaded were never called.
////////////////////////////////
this.my_mcl = new MovieClipLoader();
this.mclListener = new Object();
this.mclListener.pparent = this;
this.mclListener.onLoadInit = function(
target_mc:MovieClip
) : Void
{
this.pparent.onEnterFrame = function() : Void
{
this.OnFrameEntry();
}

this.pparent.OnLoaded();
}
this.my_mcl.addListener(mclListener);
////////////////////////////
}
/**
* destroy method
*/
public function Destroy():Void
{
_visible = false;
this.unloadMovie();
}
public function Load(
inAniName :String,
inRepeats :Number
) : Void
{
_visible = true;
mRepeats = inRepeats;
mAniName = inAniName;
my_mcl.loadClip(inAniName,this);
this.stop();
}
public function LoadNPlay(
inAniName :String,
inRepeats :Number
) : Void
{
_visible = true;
mRepeats = inRepeats;
mAniName = inAniName;
my_mcl.loadClip(inAniName,this);
//TBD
}
public function Play() : Void
{
if(mAniName == "")
{
return;
}
_visible = true;
this.gotoAndPlay(1);
}
public function Stop() : Void
{
_visible = false;
this.gotoAndStop(1);
}
public function Resume() : Void
{
if(mAniName == "")
{
return;
}
//TBD
this.play();
}
public function Pause() : Void
{
//TBD
this.stop();
}
public function OnLoaded() : Void
{
trace("OnLoaded");
}
public function OnRound() : Void
{
_global.GLDXI_AniRounded(mAni);
}
public function OnEnd() : Void
{
trace("OnEnd");
_visible = false;
_global.GLDXI_AniFinished(mAni);
}

public function OnFrameEntry() : Void
{
trace("OnFrameEntry");
if(this._currentframe == this._totalframes)
{
mCurrentRepeat++;
if(mCurrentRepeat >= mRepeats)
{
mCurrentRepeat = 0;
OnRound();
OnEnd();
this.stop();
}
else
{
OnRound();
}
}
}
}

How Do I Call Methods In Another Class?
Hi all,

I have a Class associated with my document root, and a class associated with a library object. I want to put the library object onto the stage and then have it call a method of the document root class when clicked on. My problem is I can't figure out how to call a method in another class. I'm trying something like this:

in the document root class definition:

public function crispy_point(point_to) trace("pointing to" + point_to);

in the library item class:

private function on_mouse_over(e:MouseEvent){
trace('mouse over');
animate_sign();
play_sound();
point_to('teachers');
}

The error I get is 'Call to a possibly undefined method point_to'.

How can I refer to my document root class from an instance of a Library object with a custom class assigned to it?

Thanks for any help!

Can Class Methods Be Set As MC Handlers?
SETUP:
I have a MX2004 project where I'm attempting to pass a movie clip to a class, and have a
method of the class act as the function for the onEnterFrame.

PROBLEM:
The class appears to lose reference to the movie clip when onEnterFrame() is called.

TO DUPLICATE:
Two files are needed, they are outlined below:

Code:
// File: bar.fla
var bar : Object;
bar = new foo(this);
and


Code:
// File: foo.as
class foo
{
var _mc:MovieClip;

public function foo(mc)
{
this._mc = mc;
this._mc.onEnterFrame = this.render;
};

public function render()
{
trace("Render: " + this._mc);
};
}
When the code runs, the trace output returns a repeated: undefined

WHen debugging, the constructer seems to properly have the movie clip I pass in. If it's possible to have render() be the handler for onEnterFrame(), what am I doing wrong?

Cheers.

Best Way To Add Methods To Built-in Class
I have a flash application that requires some extensions to the Date an other classes. I currently do this like:


ActionScript Code:
Date.prototype.addMilliseconds = function(milliseconds)
{
    this.setTime(this.getTime() + milliseconds);
};


This works fine but causes compile-time errors for a AS2 class that is bound to a movieclip, which uses these methods. The code works, I just get the errors when compiling. Presumably the compier isn't aware of my extensions because it compiles the movie clip class before my class extensions, which are in a seperate include, loaded in frame 1.

So i guess my question is, how can I get it to compile the extensions to Date class, before it compiles my movie clip classes, so that it'll know that these extra methods are available, and not give errors.

Thanks

Help. Some Class Methods Not Getting Called
I'm in the process of writing my first ActionScript class and have run into a problem where two of my defined methods aren't getting called. Could some kindly guru take a look and point out what I'm doing wrong?

Thanks,

Ken

P.S. the purpose of this class is to encapsulate drag behavior.

// in action layer
Dragger = function(x, y, timeline, graphicID, depth)
{
this.x = x;
this.y = y;
this.timeline = timeline;
this.graphic = this.attachGraphic(graphicID, depth);
trace(this.graphic);
this.scale = 100;
this.wasDragged = false;
this.render();
}

Dragger.prototype.attachGraphic = function (graphicID, depth)
{
var newName = graphicID + "_" + depth;
this.timeline.attachMovie(graphicID, newName, depth);
return this.timeline[newName];
}

Dragger.prototype.render = function()
{
with (this.graphic)
{
_x = this.x;
_y = this.y;
}
}

// the next two methods don't seem to get called as their embedded messages never appear in the trace window
Dragger.prototype.onPress = function()
{
trace("item pressed");
}

Dragger.prototype.onRelease = function()
{
trace("item released");
}

this.timeline.addListener(this);


// in test layer
obj = new Dragger(0,0,this,"circleMC",100);

// this.graphic renders to stage OK

// clicking in the shape defined by this.graphic produces no output

Referencing An Mc Created In One Class From Another Class
Hello everybuddy,

Cracking site, I normally don't post but have read and learned much from here thanks to all the posters!

I'm struggling with AS3 at the moment, forcing myself to take an OO approach and slowly getting there... However I'm now stuck...

My project is a dynamically generated web page, getting pics and data from xml files.

I have a button class that creates buttons based on an xml file, this is in its own class file(buttons.as) which is called from my document class.

The document class also creates a bunch of thumbnails using (screen.as), the thumbnails are placed in an MC called thumbs (which created by the document class).

What I need now is a way of linking my button class to the thumbs MC, so that when I click a button my thumbs MC is tweened using my dotween function.

when I run my project i get an errror from my buttons.as --> 1120: Access of undefined property thumbs.

I guess what i'm asking is how to reference an MC created in one class, from another seperate class. I thought that by setting it to public this would be possible but its not working...

Here is my code:




Code:
//Document.as
package {
import flash.display.MovieClip;
public class Document extends MovieClip {
public var thumbs = new MovieClip;
public var butArr = new Array;
public var screen1:screen;
public var thumbArr = new Array;
public function Document() {
//add buttons
for (var i:uint = 0; i < 10; i++) {
button[i] = new buttons(i);
addChild(button[i]);
}

//add thumb container
this.addChild(thumbs);
//addthumbs
for (var i:uint = 0; i < 10; i++) {
var thumbleft:uint=140+i*320;
thumbArr[i] = new screen(thumbleft,275,i,320,240,"thumb");
thumbs.addChild(thumbArr[i]);
}

screen1 = new screen(140,35,1,640,240,"home");
addChild(screen1);
}
}
}

Code:
//buttons.as
package {
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.text.*;
import flash.filters.GlowFilter;

import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
public class buttons extends MovieClip {
public var num:uint=1;
public var myXML:XML;
public var thisText =thisText;
public var thisID:uint = thisID;
public function buttons(thisID) {
this.num=thisID;
getXML();
}
public function getXML() {
var urXML:URLRequest;
var ulXML:URLLoader;
urXML=new URLRequest("buttons.xml");
ulXML = new URLLoader(urXML);
ulXML.addEventListener(Event.COMPLETE, xmlLoaded);
ulXML.load(urXML);
}
public function xmlLoaded(event:Event) {

myXML = XML(event.target.data);

var xmlID=thisID-1;
thisText=myXML.butTitle[this.num];

makeButton(thisText);
}
public function makeButton(thisText) {
var myTextField:TextField=new TextField;

// Here we add the new textfield instance to the stage with addchild()
addChild(myTextField);

// Here we define some properties for our text field, starting with giving it some text to contain.
// A width, x and y coordinates.
myTextField.text=thisText;
myTextField.width=120;
//myTextField.height=50;

myTextField.multiline = true;
myTextField.wordWrap = true;
myTextField.x=15;
myTextField.y=this.num*50+50;

// Here are some great properties to define, first one is to make sure the text is not selectable, then adding a border.
myTextField.selectable=false;
//myTextField.border=true;

// This last property for our textfield is to make it autosize with the text, aligning to the left.
//myTextField.autoSize=TextFieldAutoSize.LEFT;

//This is the section for our text styling, first we create a TextFormat instance naming it myFormat
var myFormat:TextFormat=new TextFormat;

// Giving the format a hex decimal color code
myFormat.color=0xFFFFFF;

// Adding some bigger text size
myFormat.size=16;
myFormat.font="SkandiaDisplay";

// Last text style is to make it italic.
//myFormat.italic=true;

// Now the most important thing for the textformat, we need to add it to the myTextField with setTextFormat.
myTextField.setTextFormat(myFormat);
this.addEventListener(MouseEvent.CLICK,changePage);
this.addEventListener(MouseEvent.MOUSE_OVER,mouseover);
this.addEventListener(MouseEvent.MOUSE_OUT,mouseout);
}
function mouseover(evt:MouseEvent):void {
var glow:GlowFilter = new GlowFilter(0xFFFFFF,0.5,5,5);
this.filters=[glow];
}
function mouseout(evt:MouseEvent):void {
this.filters=[];
}
function changePage(evt:MouseEvent):void {
var newPage:Number=evt.currentTarget.num;
trace(newPage);


//not working
//1120: Access of undefined property thumbs.
thumbs.dotween("x",700,460);
}

public function dotween(command,startVal, endVal) {
var myTween:Tween = new Tween(this,command, None.easeOut, 0, 1, 1, true);
}
}
}
Any help would be greatly appreciated!!!

Thanks in advance!

Calling Base Class Methods Of Same Name
I am writing an application which uses a few levels of inheritance.
ie, A is the base class
B inherits from A
C inherits from B

The inheritance seems OK, except when I am trying to explicitly call a base class method from within a subclass method of the same name.

In the first example things seem to work OK, I can call A::fn() from within B::fn().
But the second example has problems, if I call C::fn(), it is not overloaded, so it calls B::fn(), which then seems to make a call to itself.

Is there a recommended way of calling base class methods of the same name?


// Example 1 START============================================= ===================

function A(l_x){
trace("A constructor: x = "+l_x);
this.name = "A object";
this.x = l_x;
}

A.prototype.fn = function(){
trace("A::fn");
trace("A::fn: x = "+this.x);
}

// inherit from A
function B(l_x, l_y){
trace("B constructor");

this.base = A;
this.base(l_x);
delete this.base;

this.y = l_y;
}

B.prototype.__proto__ = A.prototype;

B.prototype.fn = function(){
trace("B::fn");

this.fnBase = this.__proto__.__proto__.fn;// copy the baseclass fn
this.fnBase();// call the fn

trace("B::fn x = "+this.x);
trace("B::fn y = "+this.y);
}

var b1 = new B(1, 2);
// call B's fn
b1.fn();


// Example 1 END ================================================== =========

// Example 2 START============================================= =============


function A(l_x){
trace("A constructor: x = "+l_x);
this.name = "A object";
this.x = l_x;
}

A.prototype.fn = function(){
trace("A::fn");
trace("A::fn: x = "+this.x);
}

// inherit from A
function B(l_x, l_y){
trace("B constructor");

this.base = A;
this.base(l_x);
delete this.base;

this.y = l_y;
}

B.prototype.__proto__ = A.prototype;

B.prototype.fn = function(){
trace("B::fn");

this.fnBase = this.__proto__.__proto__.fn;// copy the baseclass fn
this.fnBase();// call the fn

trace("B::fn x = "+this.x);
trace("B::fn y = "+this.y);
}


// inherit from B
function C(l_x, l_y, l_z){
trace("C constructor");

this.base = B;
this.base(l_x, l_y);
delete this.base;

this.z = l_z;
}

C.prototype.__proto__ = B.prototype;


var b1 = new B(1, 2);
// call B's fn
b1.fn();

var c1 = new C(1, 2, 3);
c1.fn();

// Example 2 END ================================================== =====

Calling Functions From Class Methods
Is it just not a good idea to call a function from within a class method? Or should a special syntax always be used?

The wackyness I notice when I call functions decared at the _root from class methods declared at the _root:

I notice that trace() cannot show anything in the output window if trace() is within a function and it is called by a class method. Calling the same function outside a method allows the trace() to work.

Passing arrays that are in a property of a class like: this.myArr from within a Class method to a function lets the function work with the array but really it is a copy of the array, not the array itself. Passing the same params to the function from outside the method works.

Maybe my syntax is wrong. Should a function declared at the root be always refered to from a class method as _root.myFunction() even if the Class and class method are at the root too?

Thanks in advance for the help.

Assigning Methods To Objects In A Class
I'm just now getting into writing classes and I want to make sure I'm not going down the wrong path with declaring my methods as "static". So, the class is used to create dropdown items, and my area of concern is where I declare the OnRollOver and OnRollOut functions. In the following exampe the only way I could trigger the assigned methods was to define the methods as "static", and include the name of the class in the path: "Dropdown.createLineItems(this._parent);". It works, but I imagine there are other ways to go about this. Any suggestions?



class Dropdown {
private var clip:MovieClip;
private var depth:Number;
private var mouseListener:Object = new Object();
private static var SYMBOL_ID:String = "dropdown_pw_proto";
//--
public function Dropdown(target:MovieClip, x:Number, y:Number) {
depth = target.getNextHighestDepth();
clip = target.attachMovie(Dropdown.SYMBOL_ID, "dropdown_pw"+depth, depth);
clip._x = x;
clip._y = y;
clip.lineitem_proto._visible = false;
clip.top.useHandCursor = false;
clip.top.onRollOver = function() {
trace(this);
Dropdown.createLineItems(this._parent);
};
clip.top.onRollOut = function() {
trace(this);
Dropdown.removeLineItems(this._parent);
};
}
//--
private static function createLineItems(clip):Void {
trace("create lines "+clip);
clip.gotoAndStop(2);
var x:Number = 0;
for (x=0; x<5; x++) {
duplicateMovieClip(clip.lineitems.lineitem_proto, "lineitem"+x, clip.lineitems.getNextHighestDepth());
var mylineitem:MovieClip = clip.lineitems["lineitem"+x];
mylineitem._y = mylineitem._height*x;
}
}
//--
private static function removeLineItems(clip) {
//trace("remove function"+clip);
clip.gotoAndStop(1);
//Mouse.removeListener(Dropdown.mouseListener);
}
}

How To Call Main Class Methods
Hi ....

I have one main class to attach MovieClip from library call "Circle" and everything was attach and display to stage smoothly...my problem is how to call a methods from this Main class form Circle MovieClip I mean inside "Circle.as" ....u can see my code below
Main.as

Code:
package{
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
import flash.events.Event;


public class Main extends Sprite{
private var _stage:DisplayObjectContainer;

public function Main(stage_:Stage){
_stage = stage_;
}

public function attachCircle():void{
var circle:Circle = new Circle();
//circle.x = 100;
//circle.y = 100;
_stage.addChild(circle);

}

public function callMe():void{
trace("foo");
}

}//end class

}
Circle.as

Code:
package{
import flash.display.MovieClip;
import flash.events.Event;

public class Circle extends MovieClip{

public function Circle(){
this.addEventListener(Event.ENTER_FRAME, moveCircle);
}

private function moveCircle(e:Event):void{
var mc:MovieClip = (e.target as MovieClip);
mc.y = 100;
if(mc.x < 400){
mc.x += 10;
}else{
mc.removeEventListener(Event.ENTER_FRAME, moveCircle);
//how to call function in main class here in another words equivalent some sort of _global function in AS2
callMe();
//it thrown this error for my attempt so far ...
//1180: Call to a possibly undefined method callMe.
}
}

}


}
Hope someone can give me some shed on light on it...really need help..tq...

Trying To Get A Class's List Of Methods Using DescribeType()
In the process of writing some Unit tests I found that I had to add each test case individually to the testSuite so I wanted to extend TestCase and have it added all my test*** methods automatically.
Aside from this I would like to get to grips with describeType()

what I have so far is

Code:
public class FlexTestCase extends TestCase
{
private var testSuite:TestSuite = new TestSuite( );

public function FlexTestCase( className:String )
{
var xml:XML = describeType( className );
var ClassReference:Class = getDefinitionByName( className ) as Class;

for each (var method:XML in xml.method)
{
testSuite.addTest(new ClassReference( method.name ));
}
}

public function suite():TestSuite
{
return testSuite;
}

}
However when I do a print out of a test run passing in a class MyClass which contains 3 methods I get the following ( see that xml from describeType indicates nothing about the 3 methods in my class 'MyClass' )
[trace] 10:29:08.610 [INFO] xml =
<type name="String" base="Object" isDynamic="false" isFinal="true" isStatic="false">
[trace] <extendsClass type="Object"/>
[trace] <constructor>
[trace] <parameter index="1" type="*" optional="true"/>
[trace] </constructor>
[trace] <accessor name="length" access="readonly" type="int" declaredBy="String"/>
[trace] </type>
[trace] 10:29:08.610 [INFO] ClassReference = [clas
s MyClass]

How To Call Main Class Methods
Hi ....

I have one main class to attach MovieClip from library call "Circle" and everything was attach and display to stage smoothly...my problem is how to call a methods from this Main class form Circle MovieClip I mean inside "Circle.as" ....u can see my code below
Main.as

Code:
package{
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
import flash.events.Event;


public class Main extends Sprite{
private var _stage:DisplayObjectContainer;

public function Main(stage_:Stage){
_stage = stage_;
}

public function attachCircle():void{
var circle:Circle = new Circle();
//circle.x = 100;
//circle.y = 100;
_stage.addChild(circle);

}

public function callMe():void{
trace("foo");
}

}//end class

}
Circle.as

Code:
package{
import flash.display.MovieClip;
import flash.events.Event;

public class Circle extends MovieClip{

public function Circle(){
this.addEventListener(Event.ENTER_FRAME, moveCircle);
}

private function moveCircle(e:Event):void{
var mc:MovieClip = (e.target as MovieClip);
mc.y = 100;
if(mc.x < 400){
mc.x += 10;
}else{
mc.removeEventListener(Event.ENTER_FRAME, moveCircle);
//how to call function in main class here in another words equivalent some sort of _global function in AS2
callMe();
//it thrown this error for my attempt so far ...
//1180: Call to a possibly undefined method callMe.
}
}

}


}
Hope someone can give me some shed on light on it...really need help..tq...

Access Methods In MC's Inherited Class
Hi,

I have a class Fader that extends MovieClip. A movieclip in my library inherits this class via the linkage dialogue. My Fader class has a public method "FadeIn". So why is it that if I put the movieclip on the stage at design time, and put this code in the first frame of my timeline:

_root.faderClip.FadeIn();

it doesn't work?

it seems that outside of the Fader class, no other clips have access to these methods.. strange.. any ideas?

thanks - Trevor

Access Variables And Methods From One Class By Another
Hi

I have a document with a document class (class1) on the stage of that document I have a MovieClip with a class attached to it using linkage (class2).

They are both part of the same package.

In class1 I have a method called "zoom":

internal function zoom(p:Number):void
{
trace(p);
}

How can I call that method from class2?

I've tried:

parent.zoom(p);

But I get the compiler error:

1061: Call to a possibly undefined method zoom through a reference with static type flash.display:DisplayObjectContainer.


Anyone?

Regards,
Jakob

Overriding Base Class Methods
I would like to write a class that extends XMLSocket. I'd like to call my class RPCSocket. Among other things, I want to add a property which indicates that the socket is 'waiting to connect'. This would mean that the connect() method of XMLSocket has been called but the CONNECT event has not yet been dispatched. I'll therefore need to override the CONNECT and CLOSE methods of XMLSocket in my class, RPCSocket.

I haven't yet seen any reason why I can't override these methods -- they are neither constant nor static nor final and do not implement an interface method (as far as I can tell) and they are inherited.

I obviously need to call the original connect() and close() methods of the XMLSocket, however. Is the attached code the proper way to do this? Can anyone see any particular problem with the attached code?










Attach Code

package {
class RPCSocket extends XMLSocket {
public var boolWaitingToConnect:Boolean = false;

public override function connect(host:String, port:int):void {
boolWaitingToConnect = true;
super.connect(host, port);
}
public override function close(host:String, port:int):void {
boolWaitingToConnect = false;
super.close();
}
}
}

Unable To Access Class Methods
I have this class linked to a movieclip. I am attemping to access navPanelClose() from another class in the same package but get the error:

1061: Call to a possibly undefined method navPanelClose through a reference with static type Class.

Here is the Class:

package classes.util{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;



public class NavInstructions extends MovieClip {

private var _timer:Timer;


public function NavInstructions() {
Glo.bal.navPanel = this;

}
public function navPanelClose() {
_timer = new Timer(30);
_timer.addEventListener("timer", easeToLoc(722,379.8));
_timer.start();
}
public function navPanelOpen() {
_timer = new Timer(30);
_timer.addEventListener("timer", easeToLoc(722, 285.5));
_timer.start();
}
private function easeToLoc(targetX:Number,targetY:Number) {
var _easingSpeed:Number = 0.1;
var dx:Number = targetX - this.x;
var dy:Number = targetY - this.y;
var dist:Number = Math.sqrt(dx * dx + dy * dy);

if (dist < 1) {
this.x = targetX;
this.y = targetY;
_timer.stop();
_timer.removeEventListener("timer", easeToLoc);
} else {
this.x += dx * _easingSpeed;
this.y += dy * _easingSpeed;


}
}
}
}

What am I missing here?

Delete Class Objects And Methods
Hi, i have created a class file for a game. Now i have 3 to 4 games in one Main File. So after playing one game user can choose another. Now can anybody tell me how to delete the first class Object or methods, which was used in First game. So that i can remove the garbage collections from Flash to make it with fast process?

Using MovieClip Methods In Custom Class
I've got a custom class (using AS2) that mostly does things like set the score and level of a game, as well as sets the player's lives on the screen. I need to unload and attach MovieClips within the Lives control function, which require those methods from the MovieClip class.

I don't think I need to extend this class from the MovieClip class, I think I need to import the class somehow. I don't know the path though..something like mx.MovieClip.* or something?

Calling Different Methods In Class Instances
Is there a way to call different methods from different class instances in 3rd class? I know it sounds confusing, but I'll try to explain what i want (:

I have 2 classes:

PHP Code:



package {    public dynamic class Box {                public function Box() {                Content.update(this);            }        }        public function changeBox(changeValue:Number):void {        }    }} 




...and:

PHP Code:



package {    public dynamic class Cylinder {                public function Cylinder() {                Content.update(this);            }        }        public function changeCylinder(changeValue:Number):void {        }    }} 




...also there is a 3rd class that's updating/calculating some stuff...


PHP Code:



package {    public class Content {        public static function update(object:*):void {            // calculate stuff...            //             // when done, call method changeBox or changeCylinder              // and pass result of calculation        }    }} 




So i need a way to call changeBox or changeCylinder methods, depending on 'who' asked for update...

I've tried several things: passing method name as argument, referencing method through public static dict: Dictionary in Content class, but can't find a way that works... Also setting return type of Content.update function to Number and passing result that way isn't solution - real example is little more complicated (: I believe function call() & apply() methods are what i really need, but can't figure out how to use them

Any ideas?

How To Call Main Class Methods
Hi ....

I have one main class to attach MovieClip from library call "Circle" and everything was attach and display to stage smoothly...my problem is how to call a methods from this Main class form Circle MovieClip I mean inside "Circle.as" ....u can see my code below
Main.as

Code:
package{
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
import flash.events.Event;


public class Main extends Sprite{
private var _stage:DisplayObjectContainer;

public function Main(stage_:Stage){
_stage = stage_;
}

public function attachCircle():void{
var circle:Circle = new Circle();
//circle.x = 100;
//circle.y = 100;
_stage.addChild(circle);

}

public function callMe():void{
trace("foo");
}

}//end class

}
Circle.as

Code:
package{
import flash.display.MovieClip;
import flash.events.Event;

public class Circle extends MovieClip{

public function Circle(){
this.addEventListener(Event.ENTER_FRAME, moveCircle);
}

private function moveCircle(e:Event):void{
var mc:MovieClip = (e.target as MovieClip);
mc.y = 100;
if(mc.x < 400){
mc.x += 10;
}else{
mc.removeEventListener(Event.ENTER_FRAME, moveCircle);
//how to call function in main class here in another words equivalent some sort of _global function in AS2
callMe();
//it thrown this error for my attempt so far ...
//1180: Call to a possibly undefined method callMe.
}
}

}


}
Hope someone can give me some shed on light on it...really need help..tq...

AS3 - How To Call Main Class Methods
Hi ....

I have one main class to attach MovieClip from library call "Circle" and everything was attach and display to stage smoothly...my problem is how to call a methods from this Main class form Circle MovieClip I mean inside "Circle.as" ....u can see my code below
Main.as

Code:
package{
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
import flash.events.Event;


public class Main extends Sprite{
private var _stage:DisplayObjectContainer;

public function Main(stage_:Stage){
_stage = stage_;
}

public function attachCircle():void{
var circle:Circle = new Circle();
//circle.x = 100;
//circle.y = 100;
_stage.addChild(circle);

}

public function callMe():void{
trace("foo");
}

}//end class

}
Circle.as

Code:
package{
import flash.display.MovieClip;
import flash.events.Event;

public class Circle extends MovieClip{

public function Circle(){
this.addEventListener(Event.ENTER_FRAME, moveCircle);
}

private function moveCircle(e:Event):void{
var mc:MovieClip = (e.target as MovieClip);
mc.y = 100;
if(mc.x < 400){
mc.x += 10;
}else{
mc.removeEventListener(Event.ENTER_FRAME, moveCircle);
//how to call function in main class here in another words equivalent some sort of _global function in AS2
callMe();
//it thrown this error for my attempt so far ...
//1180: Call to a possibly undefined method callMe.
}
}

}


}
Hope someone can give me some shed on light on it...really need help..tq...

XML In A Class: Waiting For XML To Load Before Calling Methods
Hi,

I'm currently trying to write a generic AS2 class to read an XML file and provide a bunch of other functions for searching, etc. which looks something like this:


Code:
class ie.io.XMLreader {
//vars
private var XMLfile:XML;

//constructor
public function XMLreader(filename:String) {
//load XML file
XMLfile = new XML();
XMLfile.ignoreWhite = true;
XMLfile.onLoad = function(success) {
if (!success) {
trace("ERROR: ie.io.XMLreader: problem reading data file.");
}
};
XMLfile.load(filename);
}

private function findNode(nodeName:String, aNode:XMLNode):XMLNode{
//recursively search aNode for node named 'nodeName'
...
}

...
}
My problem is that if I then use this class in the main timeline, eg:


Code:
import ie.io.XMLreader;

reader = new XMLreader('test.xml');
trace(reader.getNodeArray("node1"));
nothing is displayed, as the XML hasn't finished loading, so cannot be searched. Is there a way to make Flash wait until the XML file is loaded before calling the methods, without having to wrap everything in the onLoad event handler?

Problem On Accessing A Component Class Methods
Hello. I'm developing a component which incorporates standart Button and TextInput components. To handle those components events, for example "click" or "change" event, i'm creating an object in main class, and creating functions attached to that object. When coding in this object scope, "this" statement for main class becoming unaccessible and pointing to current object context. Is there a way to access class dynamic methods or variables from sub-object context? Example:

class something extends UIComponent {
...
private var btnOk:Button;
private var btnOkEvent:Object;
public function something() {
...
}
public function init() {
btnOkEvent.click = function(objEv) {
//In this context "this" statement does not point to
//something class. I mean i couldn't call beginDraw()
//method from here.
//(I know, if beginDraw method begins with static
//keyword, i can call it like something.beginDraw() )
}
btnOk = Create("Button"); //Sample
btnOk.addEventListener(btnOkEvent);
}
private function beginDraw() {
...
}
/*
I know, i can use class it self with event-name functions to handle
other components events but there must be an another way.

public function init() {
...
btnOk.addEventListener(this);
}
private function click(objEv) {
...
}

*/
}

This is a general question/problem for me. Perhaps it has a very simple answer, but i don't know. Is there a way? If so, how? Please help!

Accessing Properties And Methods Of MC Base Class
I have a bunch of movieclips on the stage. I assigned each the base class of "Country". Now when I try to access the properties of each like this:


ActionScript Code:
for(var i:int=0; i<worldMap_mc.numChildren; i++)
{
    worldMap_mc.getChildAt(i).selected = false;
}

I get an error saying that the property or method is undefined. Now in the linkage of each movieclip I have "Country" as the base class because if I put it in as just the class, I get an error saying that it needs to be a unique class name.

How to I access the properties and methods of the class instances on the stage without using an instance name?

Accessing Document Class Methods From Within MovieClip
Let's say I have a FLA file with document class called main. In main, let's say I have a method called test1 that just outputs "hello world" via trace. On the FLA I have a movie clip. In that movie clip, when the timeline reaches frame 123, I want it to invoke the test1 method (I just set up a simple action on the frame). However, I get an error saying that the method is undefined. I try this.parent.test1() too but that gives me the same error. Is it not possible to invoke a document class property from within the timeline of a movie clip that's on the stage?

Problems Adding Methods To String Class
I'm trying to add some new methods to the built in String class. I've tried two new methods so far. One of them (entitiesConvert, which is by far the most complex) seems to work OK (at least, it doesn't give any compiler errors). The other (pad, which is just a few lines of code) doesn't. Whenever I use the new pad() method, either inside the entitiesConvert method, or elsewhere in my code, I get a "no such method" error.

My code is below. Can anyone see what's wrong with the pad() method?

Thanks - Rowan

// String pad method.
// If len is negative, pads on the left, if positive, to the right.
// Pads to length abs(len) with the first character of str.
// str defaults to " ".
String.prototype.pad = function(len:Number, str:String):String
{
var abslen:Number = Math.abs(len);
var s = abslen-this.length;
if (s <= 0) return this;
if (!str.length)
{
str = " ";
}
else
{
str = str.substring(0,1);
}
var p = "";
while (s > 0)
{
p += str;
s--;
}
if (len >= 0)
{
return (this + p);
}
else
{
return (p + this);
}
}


// Convert HTML entities into their corresponding Unicode characters
String.prototype.entitiesConvert = function():String
{
var str:String = this;

// create the entity mapping array
// which allows decoding html entities into their unicode equivalents
var aryEntities:Object = new Object();

aryEntities["&nbsp;"] = "u00A0"; // non-breaking space
aryEntities["&iexcl;"] = "u00A1"; // inverted exclamation mark
aryEntities["&cent;"] = "u00A2"; // cent sign
aryEntities["&pound;"] = "u00A3"; // pound sign
// Lots more entities go here...

for(var entity:String in aryEntities)
{
str = str.split(entity).join(aryEntities[entity]);
}

var strptr:Number = 0;
var begnum:Number;
var endnum:Number;
var numstr:String;
var numtyp:String;
var num:Number;
while ((begnum = str.indexOf("&#", strptr)) > -1)
{
if ((endnum = str.indexOf(";", begnum + 2)) > -1)
{
numstr = str.substring(begnum + 2, endnum);
numtyp = numstr.substring(0, 1);
if (numtyp == "x" || numtyp == "X")// Hex number.
{
if ((num = parseInt(numstr.substring(1), 16)) == NaN)// Not a valid hex number.
{
strptr = endnum + 1;
continue;
}
}
else// Decimal number.
{
if ((num = parseInt(numstr)) == NaN)// Not a valid decimal number.
{
strptr = endnum + 1;
continue;
}
}
// The first version of this line causes a "no such method" error
// str = str.substring(0, begnum) + "u" + num.toString(16).toUpperCase().pad(-4,"0") + str.substring(endnum + 1);
// The second version of this line compiles without error.
str = str.substring(0, begnum) + "u" + num.toString(16).toUpperCase() + str.substring(endnum + 1);
}
else
{
strptr = begnum + 2;
}
}
return str;
}

User Defined Class - Properties & Methods
If I create a class and set up one property which is a variable initiated at the start of the class but not within a function or a constructor and I reference the property from the .fla in a for loop as:

Book is the class and myBook is the new object.

myBook:Book = new Book(); // (fla script).

for(var prop in myBook) {
trace(prop);
}

the .AS contains

Class Book
{

var myProp:Number = 0;

function Book() {
}

}

The trace does not return anything. However when I include myProp (the class variable) in a function (other than Book function) and call that function from the .fla then the trace works and I can see myProp.

I would be grateful if someone could explain: Do I need to include Class variables in called functions (methods of the Class) in order for them to be properties of the Class?

thanks in advance

Dictionary Class: Time Complexity Of Methods
Hi,

does anyone knows the "time complexity" of Dictionary class methods ?

for example, is the ""get"" is an o(1) time complexity ?

(
import flash.display.Sprite;
import flash.utils.Dictionary;

var groupMap:Dictionary = new Dictionary();

// objects to use as keys
var spr1:Sprite = new Sprite();
var spr2:Sprite = new Sprite();
var spr3:Sprite = new Sprite();

// objects to use as values
var groupA:Object = new Object();
var groupB:Object = new Object();

// Create new key-value pairs in dictionary.
groupMap[spr1] = groupA;
groupMap[spr2] = groupB;
groupMap[spr3] = groupB;

what is the timeorder of the operation: 'groupMap[spr1]' ??
)




and another question in the same topic,
how does the Dictionary "generate" an 'equal function' & 'hashcode' (assuming same implementation as in java's HashMap) from the object passed as a key? is it efficient ?

thanks,
Eran.

MM Prototyping UIObject Methods To MovieClip Class, Why?
How did this get by a code walk at MM? Did they outsource their component creation, cuase I've always been told MM was against prototyping built-in objects?

All, of these methods are obviously used on Movieclips inside the components, so I can't figure out why they didn't just extend the movieclips being used, instead of dirtying up every movieclip in a users movie.

class mx.core.ext.UIObjectExtensions

Code:
// add stuff to MovieClip
var mc:Object = MovieClip.prototype;
mc.getTopLevel = ui.getTopLevel;
mc.createLabel = ui.createLabel;
mc.createObject = ui.createObject;
mc.createClassObject = ui.createClassObject;
mc.createEmptyObject = ui.createEmptyObject;
mc.destroyObject = ui.destroyObject;

// add CSS style processing
mc.__getTextFormat = ui.__getTextFormat;
mc._getTextFormat = ui._getTextFormat;
mc.getStyleName = ui.getStyleName;
mc.getStyle = ui.getStyle;

class mx.managers.DepthManager

Code:
// Only one depth manager is needed. When created it adds the methods to the
// base classes
function DepthManager()
{
MovieClip.prototype.createClassChildAtDepth = createClassChildAtDepth;
MovieClip.prototype.createChildAtDepth = createChildAtDepth;
MovieClip.prototype.setDepthTo = setDepthTo;
MovieClip.prototype.setDepthAbove = setDepthAbove;
MovieClip.prototype.setDepthBelow = setDepthBelow;
MovieClip.prototype.findNextAvailableDepth = findNextAvailableDepth;
MovieClip.prototype.shuffleDepths = shuffleDepths;
MovieClip.prototype.getDepthByFlag = getDepthByFlag;
MovieClip.prototype.buildDepthTable = buildDepthTable;

// applyDepthSpaceProtection();
}

Class Vs. Instance: Accessing Public Methods
I have a Segment class and instances of the segment class. Public functions called from the class itself fail, where functions called from instances work. Example:


Code:

import Scripts.Segment; // my class
import flash.geom.Point;

var p1:Point = new Point(1, 3);
var p2:Point = new Point(7, 4);
var p3:Point = new Point(4, 5);
var p4:Point = new Point(5, 1);

var mySegment1:Segment = new Segment(p1, p2); // generate two instances
var mySegment2:Segment = new Segment(p3, p4);

var p5:Point = mySegment1.intercept(mySegment1, mySegment2); // works
var p6:Point = Segment.intercept(mySegment1, mySegment2); // gives me an error
Error looks like this, by the way:
1061: Call to a possibly undefined method intercept through a reference with static type Class.

How do I access the methods without using an instance? Like the way one might use Point.distance(p1, p2)?

MM Prototyping UIObject Methods To MovieClip Class, Why?
How did this get by a code walk at MM? Did they outsource their component creation, cuase I've always been told MM was against prototyping built-in objects?

All, of these methods are obviously used on Movieclips inside the components, so I can't figure out why they didn't just extend the movieclips being used, instead of dirtying up every movieclip in a users movie.

class mx.core.ext.UIObjectExtensions

Code:
// add stuff to MovieClip
var mc:Object = MovieClip.prototype;
mc.getTopLevel = ui.getTopLevel;
mc.createLabel = ui.createLabel;
mc.createObject = ui.createObject;
mc.createClassObject = ui.createClassObject;
mc.createEmptyObject = ui.createEmptyObject;
mc.destroyObject = ui.destroyObject;

// add CSS style processing
mc.__getTextFormat = ui.__getTextFormat;
mc._getTextFormat = ui._getTextFormat;
mc.getStyleName = ui.getStyleName;
mc.getStyle = ui.getStyle;

class mx.managers.DepthManager

Code:
// Only one depth manager is needed. When created it adds the methods to the
// base classes
function DepthManager()
{
MovieClip.prototype.createClassChildAtDepth = createClassChildAtDepth;
MovieClip.prototype.createChildAtDepth = createChildAtDepth;
MovieClip.prototype.setDepthTo = setDepthTo;
MovieClip.prototype.setDepthAbove = setDepthAbove;
MovieClip.prototype.setDepthBelow = setDepthBelow;
MovieClip.prototype.findNextAvailableDepth = findNextAvailableDepth;
MovieClip.prototype.shuffleDepths = shuffleDepths;
MovieClip.prototype.getDepthByFlag = getDepthByFlag;
MovieClip.prototype.buildDepthTable = buildDepthTable;

// applyDepthSpaceProtection();
}

How To Access Methods And Properties Of The Main Document Class
How can I access methods and properties of the main document class from other classes?
Can anybody give me a hint what am I doing wrong?

I am using ActionScript3 within Flash CS3 with strict error checking on. I have an application with several custom classes:

1. The MainMovie class is associated with the document.

2. The SomeMovieClip class is associated in the library with a movie clip symbol and an instance of the symbol is placed on the main timeline.

At compilation Flash returns this error message: "1061: Call to a possibly undefined method [method name here] through a reference with static type flash.display:DisplayObject."

I get the same error if I replace the undelined code above with this:

root.gotoAndStop("aFrameLabel");


If I replace the same code simply with:

trace(root)

Flash returns [object MainMovie], which tells me it recognizes the document class.

However, if I turn the strict error checking off, the compilation finishes and the movie works as expected in all cases.









Attach Code

package myProject {
import flash.display.*;

public class MainMovie extends MovieClip{
public function MainMovie(){
}

public function aCustomMethod ():void {
trace ("Hello World")
}
}
}


package myProject {
import flash.display.MovieClip;
import flash.events.MouseEvent;

public class SomeMovieClip extends MovieClip{
public function SomeMovieClip(){
addEventListener(MouseEvent.MOUSE_UP, mouseRelease);
}

private function mouseRelease (event:MouseEvent):void {
root.aCustomMethod ():
// ----------------------------------------------
}
}
}

























Edited: 06/16/2008 at 02:37:13 PM by yr-cq

Overriding Non-AS3 Namespace Accessor Methods Using Class Prototypes
Quote:




If you do not use the AS3 namespace, an instance of a core class inherits the properties and methods defined on the core class's prototype object.




Is it possible to redefine the accessor methods for a property of a core class instance by using the prototype object of that class while using the ECMAScript/non-AS3 namespace? For example, could DisplayObject#mouseX be redefined this way?

I would guess that it isn't possible, as there isn't really an analogous prototype-based syntax for the accessor method definition syntax. It would be pretty neat if this could be redefined, though, which is why I am asking.

Also, how are accessor methods (internally) defined for core classes when not using the AS3 namespace?

Document Class, Display Object, Methods, Order
When you write a document class, and have a method of that class called on frame 1 of the timeline, that tells the playhead to go to frame 10, and on frame 10 you have a movie clip, and in that function where you goto And Played, you also called this.checkForClip();, and checkFoCclip traces out the instance name of the clip that is on stage... why does it not know it's there until some time in the future (86 milisecondsish) when the ENTER_FRAME event fires... ?

Basically, how do you know from your document class, about movie clips that exist somewhere on the time line other than frame 1?

var

Calling Methods And Properties Of Obj On The Stage While Inside A Class
How can a class that i made call an object in the main timeline? I know this sounds noobish but i can't get it to work =(

I have a redContainer_mc in my main timeline. Then in my code i have something like...

var redBall:MovieClip;
redBall = new RedBall();
redContainer_mc.addChild(redBall);


I have a couple of questions...

1. In my RedBall.as, I trace this.parent.parent and the output is Main Time Line. Why can't I do something like: trace(this.parent.parent.redContainer_mc.height)? i get this error message:

1119: Access of possibly undefined property redContainer_mc through a reference with static type flash.displayisplayObjectContainer.

how can i call the properties and methods of redContainer_mc inside my RedBall.as?



2. Btw, in my library, i have a symbol mcRedContainer, and redContainer_mc is an instance of it. When i click the linkage, and export it for action script, and run my program... i get an error message:

1046: Type was not found or was not a compile-time constant: redContainer_mc.

If i do not export it for action script, the program works fine.... Why is this? And is this question related to my question above?

How Do I Make My Custom Math Class Methods Persist Across Levels?
Well, just what the title says.

On _level0 I've added a couple of tween calcuations to the Math object. Let's call it Math.calcTween(). I would have expected this to become available through the Math object in my other SWF that I load in _level1, but that doesn't seem to be the case. Have do I make the Math object update persist across all files and levels? Does the _global keyword have anything to do with it?

Cheers,
Terpentine

Probelms Referencing A Class
Basically I have a class which extends EventDispatcher (DropDownMenu) and creates instances of another class(MenuButton) dynamically the first class is a menu the second the menu buttons for that menu.


It was all working fine until I make and instance of the dropdown menu which then makes instances of buttons and although the classpath is correct it will not make an instance of the button

this["menuMC"+i] = new MenuButton(dropMenu_mc, p_obj.eventName, 1, 1, p_obj.txt, "VP-100-256-639", "icon_mc", p_obj.iconType, 10, yPos);

unless I first declare this["menuMC"+0] = new MenuButton(); explictily in DropDownMenu constructor which defeats the dynamicnesss of it as I dont want to predeclare the vars because I dont know how many buttons there are going to be.

Has anyone experienced anything like this - its like the class has no scope in the parent class unless it is first declared in constructor - any help would be appreciated.

AS2 Class Object Referencing
Okay, so I have an object which is derived from mty DrawGrid3d class which works lovely. The draw3d class extends the movie clip class and has a constructor methos which believe it or not builds a 3d grid. Now I cant seem to be able to refer to the objects properties in any way. for example the code below traces out 'undefined'.
Any ideas?
Cheers


Code:
my_grid3d=new DrawGrid3D(_root,130,100,16,16,12,18,176,5.9,0xC5D7FE,0xFFFFFF)


trace("GRID IS:"+my_grid3d._x)

Copyright © 2005-08 www.BigResource.com, All rights reserved