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




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?



ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 03-07-2007, 01:59 PM


View Complete Forum Thread with Replies

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

[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.

Referencing A Instance Inside A Class
Hi --

I am working on converting a movie clip to a Class so that I can more easily
reuse it in later projects.

I have pretty succesfully converted my AS code from my include file to a
Class file. However, I have two objects on the stage, topBG and botBG and
whenever I reference these items inside my code, such as botBG._y I get an
error at compile time saying "There is no property with the name 'botBG'"
How can I set it so these assets can be referred to inside my code?

The code worked fine when it was just a movie.. Also, this is ActionScript
2.0.

Thanks

Rich

[as2.0 Class] Accessing Instance Variables From A Static Function.
is there some trick to accessing instance variables from a static function?

Referencing Class Variable From Inside Self
I have a class in an external .as called CustomGroup, and it will take in and process a number of objects which I want to name.

Code:
var myGroup:CustomGroup = new CustomGroup();
var otherGroup:CustomGroup = new CustomGroup();

myGroup.storeMarkers(someArray);
otherGroup.storeMarkers(otherArray);
I would like for each marker in someArray to be indexed with the instance name of the class object (i.e. "myGroup001", "myGroup002", "myGroup003") and ("otherGroup001", "otherGroup002", "otherGroup003")... but I cannot figure out how to target the class variable name from inside itself.

Help?

[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.

Accessing Document Class From Static Class?
I am building a family tree like tree in flash.

I have a package TreeManager which holds all my classes.

The document class TreeManaager.Tree controls adding new nodes to the stage.


ActionScript Code:
public function addProfile(relationship:Object):void
{
    profile = new Profile();// create new profile

    var align:Alignment = new Alignment();//make Alignment object
...

The profile class controls all the internal node functionality.

Question - If I have a button in my node MC (profile class) which should add a new relationship (i.e. call addProfile) how to I do this?


ActionScript Code:
public class Profile extends MovieClip {
       
public function Profile ():cool:
{
    this.addEventListener(MouseEvent.CLICK,Tree.addProfile);

This always throws an error. I can just add the buttons events from the document class, but it would be helpful to know if you can access the document class from a packaged static class?


ActionScript Code:
// add button events
profile.mother.addEventListener(MouseEvent.CLICK,addRelationship);
profile.brother.addEventListener(MouseEvent.CLICK,addRelationship);
profile.son.addEventListener(MouseEvent.CLICK,addRelationship);

Access On A Frame A Class Instance Variable
I have the following class:


Code:
class KeyboardTester extends MovieClip {

var output:TextField;
var keyboard:OnScreenKeyboard;
var text:String;
var frameCounter:Number;

function KeyboardTester() {

//Create a keyboard and position it on the stage
keyboard = OnScreenKeyboard.place(this);
keyboard._y = Math.ceil( output._y + output._height )+1;
keyboard._x = 1;

//Start listen for what the user types
//Listener for EVENT_OUTPUT instead of EVENT_KEYPRESSED,
//EVENT_KEYPRESSED would return us things like notification of when
//the left shift key is pressed, which we don't care about
keyboard.addListener(OnScreenKeyboard.EVENT_OUTPUT,this);

//Reset this timer. We use it to create a blinking cursor
frameCounter = 0;
//User html text so we can create our blinking cursor effect
output.html = true;

//Reset the text the user has typed
text = "";

//Refresh the stage
repaint();
}

/**
*
* This class is called by the onscreen keyboard whenever a user types
* output of interest.
*
*/
function receiveOutput(evnt:Object):Void {

//Handle backspace input
if (evnt.data == "backspace") {
text = text.substring(0,text.length-1);
//Append any standard input
} else {
text += evnt.data;
}
repaint();
}


function repaint(Void):Void {
//Simulate a cursor by alternating the font color of a pipe at the end
var interval:Number = 10;
if (frameCounter % interval > interval/2) {
output.htmlText = text+"<font color='#ffffff'>|</font>";
} else {
output.htmlText = text+"|";
}
output.scroll = output.maxscroll-1;
}

/**
*
* Repaint to make a blinking cursor
*
*/
function onEnterFrame(Void):Void {
frameCounter++;
repaint();
}

}
Could anyone tell me how to access on a frame the variable output, so as to take the typed value in a textfield from an on-screen keyboard and search an xml file?
Thanks apriori.

Checking To See If One Instance Of Class Hits Other Instances Of The Same Class?
Hi guys, the idea is similar to Yugop.com JAMPACK 01.

Let's say i have a bunch of balls/cells. I'm having trouble figuring out how to make it so that every other ball bounces off of every other ball.

so in short, it's really one instance being able to check all other instances of the same ball class?

any ideas guys and if you dont know what im talking about, please feel free to state that also.

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!

Delete Instance Of Class From Class' Method
So I have a class called Unit. When I use this class in a .fla file, I create it by saying:

var unit00:Unit = new Unit(...);

So then it creates a gfx representation of the screen for me. I would like to have a method like this:


PHP Code:



public function remove ():Void {   unit_mc.removeMovieClip();   //deleting the gfx representation of the class in the .fla   delete instance of this;   //I want to delete the variable that references the instance of this class} 




So how do I get this to work? I know that delete this will not work when defined inside the class. How do I target the .fla's instance name when I don't know what it will be called?

Thanks for any assistance

Instance Of Class Inside Of Different Class
I am trying to make an instance of a class inside of a different class. But I am getting an error:
**Error** C:Documents and SettingsOwnerDesktopSlideshowsFlashReminderE vent.as: Line 8: A class's instance variables may only be initialized to compile-time constant expressions.
var s1:Step = new Step();

**Error** C:Documents and SettingsOwnerDesktopSlideshowsFlashReminderE vent.as: Line 9: A class's instance variables may only be initialized to compile-time constant expressions.
var s2:Step = new Step();

**Error** C:Documents and SettingsOwnerDesktopSlideshowsFlashReminderE vent.as: Line 10: A class's instance variables may only be initialized to compile-time constant expressions.
var s3:Step = new Step();

**Error** C:Documents and SettingsOwnerDesktopSlideshowsFlashReminderE vent.as: Line 11: A class's instance variables may only be initialized to compile-time constant expressions.
var s4:Step = new Step();

**Error** C:Documents and SettingsOwnerDesktopSlideshowsFlashReminderE vent.as: Line 12: A class's instance variables may only be initialized to compile-time constant expressions.
var s5:Step = new Step();

**Error** C:Documents and SettingsOwnerDesktopSlideshowsFlashReminderE vent.as: Line 13: A class's instance variables may only be initialized to compile-time constant expressions.
var s6:Step = new Step();

The code for the first class is:
code:
class Event {
var type:String = new String();
var oName:String = new String();
var description:String = new String();
var steps:Number = new Number();
var dueDate:String = new String();
var percent:Number;
var s1:Step = new Step();
var s2:Step = new Step();
var s3:Step = new Step();
var s4:Step = new Step();
var s5:Step = new Step();
var s6:Step = new Step();
function createNewEvent(d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11) {
type = d1;
oName = d2;
description = d3;
steps = d4;
dueDate = d5;
percent = 0;
if (steps == 6) {
s1.createNewStep(d6);
s2.createNewStep(d7);
s3.createNewStep(d8);
s4.createNewStep(d9);
s5.createNewStep(d10);
s6.createNewStep(d11);
} else if (steps == 5) {
s1.createNewStep(d6);
s2.createNewStep(d7);
s3.createNewStep(d8);
s4.createNewStep(d9);
s5.createNewStep(d10);
} else if (steps == 4) {
s1.createNewStep(d6);
s2.createNewStep(d7);
s3.createNewStep(d8);
s4.createNewStep(d9);
} else if (steps == 3) {
s1.createNewStep(d6);
s2.createNewStep(d7);
} else if (steps == 2) {
s1.createNewStep(d6);
s2.createNewStep(d7);
} else if (steps == 1) {
s1.createNewStep(d6);
}
}
function showPercent() {
for (var p = 1; p<=steps; p++) {
percent += this["s"+p+""].percent;
}
percent /= steps;
return percent;
}
function done(stepN) {
this["s"+stepN+""].done();
}
function setStepPercent(stepN, p) {
this["s"+stepN+""].setPercent(p);
}
}

The class being loaded is:
code:
class Step{
var completed:Boolean = new Boolean();
var sName:String = new String();
var percent:Number = new Number();
function createNewStep(d1){
completed = false;
sName = d1;
percent = 0;
}
function setPercent(tbs){
percent = tbs;
}
function done(){
completed = true;
percent = 100;
}
}

Please help!!!

How Do I Refer To A Class Instance From Another Class?
Trying to get my head around scope here... I have the following in my root DocumentClass:

var horse1:Horse = new Horse();
var odds:OddsBox = new OddsBox();

From within the Horse class, how can I now refer back to the odds OddsBox instance?

My instinct is to type:
trace(_root.odds);
but that obviously doesnt work here.

Do I have to pass the odds var into the Horse class, in which case, would it have to be declared before the horse1 instance? If so, what if that is not possible - how do I refer to an outside class if it was declared after the calling class was declared?

Thanks lots

[AS2] Self Reference To A Class Instance Within A Class
Hello people!

The question says it, how can I self refer to an instance of a class within the class definition file?

Here is an example


PHP Code:



public function fireBullet(target:MovieClip) {
        Bullet_mc = target.attachMovie("Bullet", "Bullet1", 1);
        }
    } 




Now everytime I want to call the function I have to put this as my target, (fireBullet(this))I cannot just put it in the code as it gives me an error. Could someone please help.

[AS2] Self Reference To A Class Instance Within A Class
Hello people!

The question says it, how can I self refer to an instance of a class within the class definition file?

Here is an example


PHP Code:



public function fireBullet(target:MovieClip) {
        Bullet_mc = target.attachMovie("Bullet", "Bullet1", 1);
        }
    } 




Now everytime I want to call the function I have to put this as my target, (fireBullet(this))I cannot just put it in the code as it gives me an error. Could someone please help.

How Do I Access A Variable Declared In My Document Class From Another Class
Hi there,

I'm pretty new to classes and am probably missing something really basic so apologies if this seems like a stupid question.

I'm trying to access a variable that I've declared in my document class from within another class.

I know I can pass the variable through when I call the class as follows:


Code:
var myBall:Ball = new Ball(5);
and pick this up in the Ball function within my Ball class as follows:


Code:
public function Ball(ballSpeed) {
trace(ballSpeed);
}
But what if I don't want to do that as I have a whole load of general global variables I want to access which were defined in my document class?

What I actually want to do is just have access to all the variables defined in the document class from within the Ball class.

I tried parent.variableName and various other ways of accessing what I need but all of them spit back errors.

Any help would be really appreciated - I'm sure this is very basic but I'm totally stuck on this.

Many thanks.
Ian

Reading Document Class Variable From A Class
I have a document class that establishes a variable called "_captioning". The document class then loads a button class that on attachChild needs to check to see if _captioning is set to true or false. I can load this class and can trace strings being generated inside the class but I can't target the _captioning variable outside of it in the document class.

I just need to see how I can get this button class to read things in the document class.

Referencing A Variable As An Instance Name
I have a set of buttons numbered 1-10, each with an instance name of b1, b2, b3 etc... depending on which button is pressed I want to move an indicator (which is an underline) to the position of that button to display to the user which page they are on. I have a variable called whichButton that I can get the value of the instance name but am having trouble actually getting the variable to be recognized as an instance name when telling the indicator to move its ._x position...

any thoughts?

function indicate() {
var button = "b";
trace(button+" this is the button prefix");
var whichButton = button+pageNum;
trace(whichButton+" this is the button Instance Name");
subNav.indicator._x = subNav.whichButton._x;
}

//whenever a button is pressed it updates pageNum with the value of that button, so button 3 when pressed pageNum = 3; and so on //

Referencing An Instance Name As A Variable?
I know this might sound like a silly question, but I've been trying to reference an instance name within a function as a variable passed into the function. For example:


Code:
ambient_emissions_monitoring.onRollOver = function(){
linkArrowView('on',this._name);
}

linkArrowView = function(offOrOn,iconPosition){
trace(_root.iconPosition._x);
}
I would like to be able to access all the properties (for example, the x coordinates) for an instance on the stage, but it returns 'undefined'. I'm fairly certain it can be done, I just cannot recall how to do so! Any help would be greatly appreciated.

thanks much!

Jon

Referencing An MC Instance By Combining Variable Strings
Hello everyone,

I know this is pretty easy and there is a specific way to do it, but for the life of me I can't remember.

I have several boxes on stage. Each have an instance name of box1, box2, box3, etc. I'd like to call a function that each time references the next box up. I've created this:




Code:
SlideStart = function(){
i++;
boxVar = "box" + i;
SlideOff(boxVar);
}



Although the variable boxVar does trace as "box1", when I pass SlideOff the value boxVar, it doesn't do anything. If I pass SlideOff the value "box1", it works fine. Can anyone clue me in?

Thanks!

Referencing Instance Name W/variable In Prototype Call
Hello all, I'm trying to reference an instance through the use of a variable in my call to a prototype. The variable is myVar and contains the instance name to which I want to apply the resizeTo prototype. My syntax is incorrect and I haven't found any clues in my search. Any help is always appreciated. Thanks.


Code:
on(release){
//disregard this line
this.swapDepths(this._parent.getNextHighestDepth());
//this is calling a prototype named resizeTo
this.resizeTo(150, -100, -100);
//Setting instance name of another movie
myVar = "green";
//Trying to drop that instance name into my next prototype call
this._parent.myVar.resizeTo(100, _parent.old_X, _parent.old_Y);
}

Static Class
May be simple question, but...
I've create a static Class. I call it on the main timeline. If I create a second instance anywhere else in the same movie, those two instance refer to the same object. I ceate instance usign MyClass.getInstance();.

Well What I try to understand is the scope of that kind of Class. ie If I load a new swf in my main movie, in that new swf, on the first frame, there is MyClass.getInstance();. But it does not seem to refer to the same object. It's like that new instance, because it is not on the same file, is now a new object???

Does it mean that Static Class Scope is only valid to the same swf file?
If I remove an swf, does it means that all instances of Static Class in a swf is also cleared of the memory at the same time. So when reloaded, all the instance are new???

I thought that static Class was create once in the memory and staying there
Tanx to helping me understand better!

AS3 What Is A Static Class?
I was wandering whether is it required that all the functions and variables must be static in order to be a static class. Like Math.random()

Or having 1 function or variable in a class is static makes it as "static class"?


Edit:
And which way is correct to write this?

public static function AyumiloveAS3():void {}
static public function AyumiloveAS2():void{}

var public static ayuTemp1:int = 0;
var static public ayuTemp2:int = 0;

[AS3] New Obj() Vs Static Class
Hi, guys.

Because we now have the luxury of creating new Sprites and MovieClips etc, I have a question about handling a "tooltip" type object.

Because there should only be one instance of the Tooltip object, would it be better to create a static class and use a Tooltip.init() method, or would it be better to create a new instance of Tooltip each time it needed to be displayed?

For example, if I created a new instance each time, the Tooltip class could contain a static property flagging whether or not another Tooltip is active. If another Tooltip is active then it is closed.

Here's a basic example of what I'm going on about...


ActionScript Code:
package {
 
    import flash.display.Sprite;
 
    public final class Tooltip extends Sprite {
 
        private static var isActive:Boolean = false;
        private static var activeInstance:Tooltip;
 
        public function Tooltip( text:String = "" ) {
            if (isActive) {
                activeInstance.close();
            }
            isActive = true;
            activeInstance = this;
            // rest of init code...
        }
 
        public function close():void {
            isActive = false;
            // rest of code...
        }
 
    }
 
}


ActionScript Code:
// Show a tooltip...
tip = new Tooltip("Click this and die!");

If none of that makes any sense then let me know.

Using Variable Defined In One Class In Another Class, How?
hi everybody. i have a variable (holdFrame) in a class that controls a pause button, so that when the pause button is pressed, the variable stores the frame number where the pause button was pressed. pressing this button takes the timeline to a frame with nothing but the word "PAUSED" and a continue button on it. i have a class for the continue button that needs to call the variable that stored the previous frame number in it, so when the continue button is pressed the timeline is returned to the previous frame.

so how do i make that variable available to the other class and how do i call that variable from the other class? they are in the same package. below is the code for the two classes.

pause button code:

Code:
package lesson
{
import flash.display.MovieClip;
import flash.events.*;

public class PauseAll extends MovieClip
{
public var holdFrame:int;

public function PauseAll()
{
this.addEventListener(MouseEvent.CLICK, pauseAll);
this.buttonMode = true;
}

private function pauseAll(e:MouseEvent):void
{
holdFrame = MovieClip(parent).currentFrame;
MovieClip(parent).gotoAndPlay(MovieClip(parent).totalFrames);
}
}
}
continue button code:

Code:
package lesson
{
import flash.display.MovieClip;
import flash.events.*;
import lesson.PauseAll;

public class ContinueAll extends MovieClip
{

public function ContinueAll()
{
this.addEventListener(MouseEvent.CLICK, continueAll);
this.buttonMode = true;
}

private function continueAll(e:MouseEvent):void
{
MovieClip(parent).gotoAndPlay(MovieClip(parent).holdFrame);
}
}
}

Tv Static Using BitmapData Class
Hi,
I found this tutorial file online.
I'm trying to have the static fade in and then expand to fill the screen.
When it fills the screen, I want the static to stay still (just a still frame of static).
Any ideas?

Thanks!

Getting An Event From A Static Class
I have a Settings/Config class. All its methods are static. The first thing I do in my swf is to load the settings in the form of an XML file. As the rest of my code relies on this file being loaded, I need to listen for an onLoad event from this Class before running it.

Can't use EventDispatcher as the 3 functions (addEventListener/removeEventListener/dispatchevent) are not static,

So how can I get an event out of it?

Thanks

How To Write A Static Class?
Hi, im familiar working with classes.
Like this:


Code:

package {
public class ClassA {
public function ClassA() {

}
public function doSomeThing() {

}}}
And then to use it:

Code:

var c:ClassA = new ClassA();
c.doSomeThing();
Problem is, I want a class i can use like this, with no instanciation:

Code:
ClassA.doSomeThing();
I believe its called a static class, can someone help med with this?
Thanks in advance...

Trying To Create A Static Class
Hi,

I am trying to create a class that gets a url and returns it.

My directories structure is: d:flashcvclasses

My fla file is in the cv folder and the as file is in the classes folder.

In my fla file I created a classpath to d:flashcv

When I run the fla file I get these errors:

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

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

I'm attaching the fla and as file, can you please tell me what am I doing wrong?

Thanks,

Sigal

Static Class In Actionscript 3.0?
Is it possible to create static class in actionscript 3.0?
like this?

ActionScript Code:
package {
    import flash.display.Sprite;
    static public class Last extends Sprite {
     function Last() {
        }
    }
}

Document Class And Static
package {

public class glo {
public static var bal:String = new String();
public function glo(){
bal="asdad";
}
}
}
This class is Document class but my fla not working?!
My fla is only ; trace(glo.bal);
WHY ?

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)

Referencing Stage From Class
Hello,
I am trying to make my first as3 class based game and so i was wondering if i could get some help. although the game wont have fancy graphics, i just would like to understand the way it works...currently, i am at a point where im getting :

1067: Implicit coercion of a value of type flash.display:Stage to an unrelated type Stage.
in my main file robot.fla, im using

var robo:robot=new robot(stage);
//var starenemy:enemy1=new enemy1(this.stage);
addChild(robo);

inside that robot.as
....
public class robot extends Sprite {
import flash.display.Stage;
private var _stage:Stage;
....
public function robot(stageRef:Stage):void {
_stage = stageRef;
...
}
amongst other things and i cant reference anything from the stage.

I think im going nuts trying to figure out how to correctly reference things to the stage. so can you take a look and guide me and tell me how i can proceed?
Attached is the zip file

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

Help Referencing A Visual MC From Another Class
I have a fla file with visual content onstage. This Fla also has a document class assigned called Home(extends Movieclip.) One of the visual assets onstage is a movieclip called mcHome that the Home class controls successfully.

I’ve got another class, Photos(extends Sprite) that I have imported(from another package) and it also successfully does what it’s suppose to. However, when I add code to Photos to refer to mcHome, the onstage movieclip, I get an


1120 access of undefined property mcHome error

What is necessary to make Photos understand what mcHome is?
Thanks

EventDispatcher/Broadcaster In A Static Class
Hey everyone,

Afaik, you need to instantiate a class to assign a listener to them. That's what I do for normal classes. I use EventDispatcher.

However, there's this class I want to modify - it's used "staticly", much like the Tween class. To clear things up, the class I'm talking about is IntervalManager by kennybunch.com

I want to modify it because I want to be able to listen when a certain interval is complete - much like a tween's onMotionFinished, only I want an onIntervalFinished.

What do I need to do to add this to the class?

Class Static Member Problem
Hi all

i've a problem as following

static function functionshowLargePic_fun(myPic) {
var loadPic_MCL:MovieClipLoader = new MovieClipLoader();
var loadPic_obj = new Object();
loadPic_obj.onLoadInit = Delegate.create(this,resize_fun);
loadPic_MCL.addListener(loadPic_obj);
loadPic_MCL.loadClip("images/"+myPic,largePic_mc);
}
static function resize_fun() {
trace ("ok")
}

error message

'this' is not accessible from this scope.
loadPic_obj.onLoadInit = Delegate.create(this,resize_fun);


What should i replace it

Thanks in advance
zerolam

How To Best Extend A Static Class To A Dynamic
i wanted to create a Label and attach another variable to it (called "link") and make it a button. However Label is not a dynamic class so i decided to do this:


ActionScript Code:
package {
   
    import flash.display.Sprite;
    import flash.display.Shape;
    import flash.events.MouseEvent;
    import flash.text.TextField;
   
    public class DynamicLabel extends Sprite {
       
        public var link:String;
       
        public function DynamicLabel(_title:String, _link:String) {
            //bg
            var _bg = new Shape();
            _bg.graphics.beginFill(0x888888);
            _bg.graphics.drawRect(0, 0, 100, 15);
            _bg.graphics.endFill();
            this.addChild(_bg);
           
            //text
            var title:TextField = new TextField();
            title.text = _title;
            this.addChild(title);
           
            //link
            this.link = _link;
           
            this.addEventListener(MouseEvent.CLICK, clickHandler);
           
            this.buttonMode = true;
        }
       
        private function clickHandler(e:MouseEvent):void
        {
            trace(e.target.link);
        }
    }
}

However when i run it and click on the "DynamicLabel" object (when the "clickHandler" function in executed) i get this error:

Code:
Property link not found on flash.text.TextField
i want to property "link" to be a part of my class, my object. Why does it look for it in the TextField?



Any workaround is greatly appreciated too All i'm trying to do is make dynamic buttons...

Way To Step Thru Properties Of Static Class?
Hi,
I have defined a class with a lot of properties (about 30). There are a number of simple methods I need to write (eg clone, copy values of all properties from one instance to another, reset values of an instance, etc).

For example

package {
[Bindable]
public class Person{
public var Var1:int;
public var Var2:int;
public var Var3:String;
....
public var VarN:Boolean;

public static function copyInto(src:Person,dest:Person): void {
dest.Var1 = src.Var1;
.....
dest.VarN = src.VarN;
}
}
}

Instead of doing lots of assignments. I'd rather do something like
for each property p in Person
dest.p = src.p

I think this can be done for dynamic classes, but what about static classes?

Thanks!

Can't Make Static Array In My Class..
I have a question class.  Each question can have child questions.  And each question will have a parent question.  My parent variable works fine but it seems that no matter what, my array is static.  In other words, each of my Questions are sharing the same Children array.  Is this a bug/feature or am I just missing something here?

Question.as
CODEclass Question {
    var QText:String;
    var QValue:String;
    var QID:String;
    var ParentID:String;
    private var Parent:Question;
    private var Children:Array = new Array();
    
    function Question() {
        trace("new question");
    }
    
    function addChild(childQuestion:Question) {
        this.Children.push(childQuestion);
        trace(this.Children.length);
    }
}

Referencing A Subclip From Within A Class File
Say I have the following movieClip Structure

myMovieClip
myMovieClip.subMovieClip

I want to make a Class file for myMovieClip

I would like this Class to reference and adjust the subMovieClip._y using commands from the class file.

I keep getting errors when trying to do this. Is this a matter of syntax or is there no way to reference another movieClip from a class file?

Thanks

Dynamic Class Referencing Question
Quick question, I'm sure this is a stupid syntax problem...


Code:
fighter1_mc.aiPattern="SwoopDown";
fighterPattern = new classes.ai_routines[fighter1_mc.aiPattern](this, 20, 1, 5, 5);
fighterPattern = new classes.ai_routines.SwoopDown(this, 20, 1, 5, 5);
The second one creates the object as it is supposed to, but the first one does not. What is the correct way to dynamically reference the object?


Thanks in Advance

Problems Referencing Parent Class
I would like to have a child access the properties of the parent class and I've read _parent allows you to reference a parent object. However, I can't seem to get it to work. Here's an example.


Code:
class test{
public var name:String;
public var Test:test2;
function test(){
name = "testSring";
Test = new test2();
}
}

class test2{
function test2(){
var This:Object = this;
trace(This._parent.name);
}

}
//in the .fla
var Test:test = new test();
If I run it, I will get "undefined".

Referencing Stage.stageWidth From A Class
I created a custom class in a .as file. I then linked this custom class with a symbol from the library in my .fla file. However, I can't reference stage.stageWidth in my custom class file. I get a null object error.

I think this happens because the custom class file is associated with a symbol on the stage and not the stage itself. For example, if I set the fla file's Document Class to the name of my custom class I can reference stage.stageWidth in the custom class. But I don't do this because I am creating multiple instances of the symbol on the stage. In order to do that properly i found I have to set the class in the properties panel of the symbol to the underlying class which then defines how each symbol behaves.

Under this type of linkage, is there a way to reference the stage width from the class?

I've tried root.stage.stageWidth and parent.stage.stageWidth to no avail. I also made sure to import flash.display.* in my custom class.

Below is the code for my .fla file and my .as file. In the .as file you'll see the line "x = Math.random() * stage.stageWidth;". This is the line giving me problems. I could hard code it, as I do for the y variable on the next line, but I'd prefer not to in order to keep the code flexible.

I also attached the files in a zip.

Any help would be appreciated.


ActionScript Code:
//.fla code

var i:int;

for(i=0; i < 100; i++){
    var myBall:flaBall = new flaBall();
    addChild(myBall);
}


//.as code

package {
   
    import flash.display.*;
    import flash.events.Event;
   
   
    public class Ball extends MovieClip{
       
        var dx:Number;
        var dy:Number;
       
        public function Ball(){
            addEventListener(Event.ENTER_FRAME, onEnterFrame2);
            reset();
        }
       
        private function reset(){
            x = Math.random() * stage.stageWidth;
            y = Math.random() * 400;
            dx = Math.random() * 20 - 10;
            dy = Math.random() * 20 - 10;
        }
       
        private function onEnterFrame2(event:Event):void{
            move();
            checkBounds();
        }
       
        private function move(){
            x += dx;
            y += dy;
        }
       
        private function checkBounds(){
            if (x > 550 || x < 0){
                dx *= -1;
            }
            if (y > 400 || y < 0){
                dy *= -1;
            }
        }
    }
}

Referencing Stage From External Class
I have an external class file that extends the MovieClip class and is linked to a movieClip on the main stage. I need it to be able to access properties of other movieclips on the main stage. How could I do this. Here is what my base movieclip class that I want to access the stage with looks like. Remember, it is linked to a movieclip on the stage, if that matters...
Obviously there is more code in the class, but I removed it for the sake of simplicity.







Attach Code

package{
import flash.display.MovieClip;
import flash.display.DisplayObject;
import Math;

public class Test extends MovieClip{

public function Test(){ //Constructor

}
}
}

Referencing Stage.stageWidth From A Class
I created a custom class in a .as file. I then linked this custom class with an symbol from the library in my .fla file. However, I can't reference stage.stageWidth in my custom class file. I get a null object error.

I think this happens because the custom class file is associated with a symbol on the stage and not the stage itself. For example, if I set the fla file's Document Class to the name of my custom class I can reference stage.stageWidth in the custom class. But I don't do this because I am creating multiple instances of the symbol on the stage. In order to do that properly i found I have to set the class in the properties panel of the symbol to the underlying class which then defines how each symbol behaves.

Under this type of linkage, is there a way to reference the stage width from the class?

I've tried root.stage.stageWidth and parent.stage.stageWidth to no avail. I also made sure to import flash.display.* in my custom class.

Any help would be appreciated.

Referencing An Object Inside A Class
and I'm trying to add an event listener and a function to the class, but I keep getting errors of undefined,
I tried just about everthing to be able to refference obj0 can anyone please help?

objGroup.obj0.addEventListener(MouseEvent.CLICK, onClick)
private function onClick (event:MouseEvent):void{

trace ("Click");

}

any help or advice will be greatly appreciated sincerely newwave
---------------this is my complete code - above code-------------feel free to use as you wish----------------------







Attach Code

package {
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.view.BasicView;

public class pv3dMyRotation2 extends BasicView {

private static const ORBITAL_RADIUS:Number = 300;
private var angle:Number = 0;
private var obj0:Sphere;
private var obj1:Sphere;
private var obj2:Sphere;
private var obj3:Sphere;
private var obj4:Sphere;
private var obj5:Sphere;
private var obj6:Sphere;
private var obj7:Sphere;
private var objGroup:DisplayObject3D;

public function pv3dMyRotation2() {
super(0, 0, true, false);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
init3D();
createScene();
startRendering();
}

private function init3D():void {

camera.x = -200;
camera.y = 0;
camera.z = 0;
}

private function createScene():void {

var light:PointLight3D = new PointLight3D(true);
light.x = 400;
light.y = 1000;
light.z = -400;

var M1:MaterialObject3D = new FlatShadeMaterial(light, 0xFF0000, 0xFFCC99);

for(var i=0; i<8; i++) {
this['obj'+i] = new Sphere(M1, 50, 10, 10);
this['obj'+i].x = ORBITAL_RADIUS * Math.cos(angle);
this['obj'+i].z = ORBITAL_RADIUS * Math.sin(angle);
angle += (360 / 8) * Math.PI / 180;
}

objGroup = new DisplayObject3D();
objGroup.addChild(obj0);
objGroup.addChild(obj1);
objGroup.addChild(obj2);
objGroup.addChild(obj3);
objGroup.addChild(obj4);
objGroup.addChild(obj5);
objGroup.addChild(obj6);
objGroup.addChild(obj7);

scene.addChild(objGroup);
scene.addChild(light);

}

override protected function onRenderTick(event:Event=null):void {
objGroup.yaw(1);
super.onRenderTick(event);
}
}
}

























Edited: 02/01/2009 at 08:58:22 PM by newwaveboats

Referencing Timeline Variables From A Class
Yet another question..How do I referece, within a class function, variables residing in the timeline that is invoking the class? (Very beginner here!)

So far I've had to send the timeline variables from the timeline to the class's function as parameters, which works, but there's so many. And I know I can just make these variables reside in _root and reference them this way, but that is not smart.

Does it have to do with _parent at all? Tried using it but failed..

Thanks.

Calling A Static Class Function From The Timeline
Hi there!

I have a (small?) problem when calling a static function in a class from the timeline:

In AS2 I used to do it like this (this code is in frame 1 of the _root timeline):


ActionScript Code:
import com.mypackage.Application;

// call to a static function main() in Application
com.mypackage.Application.main();

how do I do this in AS3, I always get this compiler error:
1202: Access of undefined property Application in package com.mypackage.

thanks for your help!!

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