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




Need Some Help With Class Variables.



TypeError: Error #1009: Cannot access a property or method of a null object reference.I have a class called Main, that extends MovieClip (it is dynamic) to house *my global* variables, functions etc.This Main class, has a particular instance variable called tower_ind, I have created an instance of this class called main.And using this right after: main.tower_ind = 5; trace(main.tower_ind); , appears to work perfectly.But if I try to access this variable from another class which I create an instance of afterwards, I get the error mentioned at the top of this post.I access it like this in the class:
Code:
var inst:String = "tower_basic1_" + this.root.main.tower_ind;
I have tried root, stage, parent, this.root, this.parent, this.stage etc etc, but no matter what, it still complains.....Although in the future I may be converting to using a public static variable of my tower class to keep hold of the index (should piss this problem right off I hope), but I will still need to get this kind of result working for other things.



KirupaForum > Flash > ActionScript 3.0
Posted on: 06-23-2007, 05:54 AM


View Complete Forum Thread with Replies

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

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

Calling SetTimeout Within Custom Class And Cannot Access The Class' Variables
Hi All,

I'm creating an user interface with Flash 8, I'm new to Flash, my background is Java therefore I decided to use ActionScript to create a custom component that is reference within an external file.

My problem I believe is scope related. I have a status bar (label component), once I update the status bar I want to call the
"setTimeout" function to wait a couple of seconds before clearing my status bar. The "setTimeout" function is executing, but for some reason my status bar is not being cleared (accessed).

Below is a snippet of my code. Any help appreciated. Thanks.


/*
External File
*/
import mx.controls.Button;
import mx.controls.Label;

class MyApp
{
//private properties
private var mc_container:MovieClip;
private var btn:Button;
private var lbl_status:Label;
private var str:String = "do see me";

//constructor
public function MyApp(target:MovieClip)
{
trace("-- MyApp --");
mc_container = target.createEmptyMovieClip("mc_container", 100);
}
//public methods
public function init(width:Number, height: Number, xPos:Number, yPos:Number):Void
{
var my_app:MyApp = this;

btn = mc_container.createClassObject(Button, "btn", 1, {label:"click me"});
btn.setSize(100, 25);
btn.move(10, 10);
btn.clickHandler = function():Void
{
trace("btn clicked");
setTimeout(my_app.clearStatus, 2400);
//correct if I call directly
//my_app.clearStatus();
trace(str);
}

lbl_status = mc_container.createClassObject(Label, "lbl_status", 2, {text:"status bar message"});
lbl_status.setSize(200, 25);
lbl_status.move(0, 50);
}
public function clearStatus():Void
{
trace("calling clearStatus");
lbl_status.text = "";
}
}


/*
Called for Flash IDE
*/
var app:MyApp = new MyApp(this);
app.init(200, 200, 0, 0);

Variables From One Class To Another Class
lets say I have a variable being set on a class but i need that variable information to be passed on to another class. Is this possible?

thanks.

Class Getting Variables From Another Class
Hello guys, I have a problem. I'm new to classes and I began with this 2 stored in different .as files: (as3_main.as and as3_library.as)


Code:
// as3_main.as
package {
import flash.display.Sprite;
impor flash.utils.*;
import as3_library;
public class as3_main extends Sprite {
var library:Class = as3_library;
public function as3_demat():void {
trace(library.variable1); // undefined
trace(library.variable2); // undefined
trace(describeType(library));
}
}
}

Code:
// as3_library.as
package {
import flash.display.Sprite
public class as3_library extends Sprite {
public var variable1:String = "hey jude";
public var variable2:String = "dont make it bad, ";
public function as3_library() {
addtext("take a sad song");
}
function addtext(e:String):void {
variable2 += e;
}
}
}
The "trace(describeType(library))" shows that the instance exists and contains 2 different variables (variable1 and variable2) but the "trace(library.variable1)" and "trace(library.variable2)" always output "undefined"... what am I doing wrong?... I will appreciate any help...


Quote:




Extra information:
Both classes are the base class for 2 different .swf files (swf_main and swf_library) which have empty stages.
* swf_main is empty.
* swf_library has en empty stage but has 3 different symbols in the library checked as export for actionscript, export for runtime sharing and export in first frame; with the following names: symbol1, symbol2 and symbol3.

Getting A Class' Variables From Another Class
I need to access a variable that exists in class B from class A.

For example:

Code attached to frame 1:

Code:


import ClassA.as;
var Person = new ClassA();

Person.FirstName = "Franz";
Person.NoNeed.init("Ferdinand");



ClassA:

Code:


var FirstName:String;
var NoNeed = new ClassB();



ClassB:

Code:


var FullName:String;
public function init(Surname:String){
FullName = ClassA.FirstName + " " + Surname;
}



The problem lies at ClassB.init() - FullName = ClassA.FirstName + " " + Surname

How do I access ClassA.FirstName from ClassB.init()?
FullName = _parent.Person.FirstName + " " + Surname does not work.

Any ideas?

Class Variables
hi all
In my class function each private member variable ,when changed affects the others in different instances of the same function. How do I stop this?

Class Variables
I have a class imported into another class.

Say for example:

package com.holderfolder {
import com.holderfolder.class1;
public class class2 extends MovieClip {
public function class2() {
//do stuff;
}
}
}

How would I call a variable declared in class2 inside of class1?

Thanks.

Class Variables
Hi to all.
I wrote a class and defined some variables in it.
But in enevt handler ( like loadVars.onLoad ) its variables is undefined.
Can any help me?
thanks a lot

Class Variables
Hi to all.
I wrote a class and defined some variables in it.
But in enevt handler ( like loadVars.onLoad ) its variables is undefined.
Can any help me?
thanks a lot

Class Variables
So I'm writing a Class in AS2 and I'm having problems in this one method. I have a method that uses a Tween class and I want to use the onMotionFinished method of the Tween class to change a class scope variable, but I seem to loose scope once I'm inside the onMotionFinished method. I'll attach the method code, but basically when I trace "this" inside the onMotionFinished, I get the Tween, and even tracing this.obj._parent doesn't give the class instance, it gives level that the tweened object was created on. "_state" is the class level variable I'm trying to change, but when I trace it from within onMotionFinished I get "undefined". Any suggestions to getting back to the class level?








Attach Code

public function show():Tween
{
new Tween(_mc.box,"_width",Strong.easeOut,_mc.box._width,100,16);
new Tween(_mc.box,"_height",Strong.easeOut,_mc.box._height,100,16);
new Tween(_mc.box,"_x",Strong.easeOut,_mc.box._x,0,16);
new Tween(_mc.box,"_y",Strong.easeOut,_mc.box._y,0,16);
new Tween(_mc.box.item_title,"_alpha",Strong.easeOut,_mc.box.item_title._alpha,100,16);
var unblur:Tween = new Tween(_mc,"blur",Strong.easeOut,4,0,16);
unblur.onMotionChanged = function()
{
this.obj.filters = [new BlurFilter(4,4,this.obj.blur)];
}
unblur.onMotionFinished = function()
{
_state = "shown";
}
return unblur;
}

Class Variables
I have created a new class called Line that extends the MovieClip class in a external .as file.

The class Line has a variable in it called XVal. (i used var XVal:Number; to declare)

I then created an instance of this using the line:
attachMovie("Line", 'line1', 100);

If i want to access the value of XVal from the instance line1 on the main timeline what syntax do i use?

cheers!

Dave

Variables In A Class
Hi there,
I had tried searching this for the last 2 hours =[ so I decided to give in and ask.

I am have a number of variables defined in my document class and I have noticed that if I were to call a function in the same class to edit the value of the variable, the change would only apply to the scope of the function.

Now I hope I used scope in the right context there =D

Here is my code to show what I mean:

ActionScript Code:
package {    import flash.display.*;    import flash.xml.*;    import flash.events.*;    import com.xml.xmlLoad;    import com.gui.mainGui;    public class main extends MovieClip {        private var _targetURL:String = "Musicinfo.xml";        private var getXMLLoad:xmlLoad;        private var getGui:mainGui;        public var xmlData:XML;        public var _lessonInfo:XMLList;         public function main() {            loadXML(_targetURL);            processXML();//This will return TypeError: Error #1009:                                //Cannot access a property or method of a null object reference.                                //at main/::processXML()            trace(xmlData);//This will also return an error similar to above        }        function loadXML(_targetURL) {            getXMLLoad = new xmlLoad(_targetURL);            getXMLLoad.addEventListener(Event.COMPLETE, onComplete);        }        function onComplete(evt:Event) {            xmlData = getXMLLoad.getXML();            trace(xmlData.fileInfo.blurb);//This traces the XML data            trace(xmlData.fileInfo.author);//And so does this        }        function processXML() {            trace(xmlData.fileInfo.blurb);//This dosen't =[        }    }}


Could someone explain why this is?
This may be a AS2 understanding but I thought that if I at changed the value of a variable made in the class, then the value would be the new value for every time the variable was called after the new value was put there.

Variables From The FLA To A AS Class
So I have this flash MP3 Player and Im passing a variable though the URL via JavaScript I can get it to Show the Variable in a text box but I need it to be used in an action script class thats in a separate .as file. Is this possible? Do you guys understand what I am asking.

For this to work I need to have the/a variable in my main fla file but needs to be used in the as class file.

Please Help.

Class Variables...
I'm having a difficult time trying to figure out class variables. The following should ouput "images/image.png" in the output window but it's saying null instead. To my understanding, the xmlLoaded function should set the private var theXML to the value of xml.... but it doesn't. This is how all of my books do it but it just isn't working for me. Is there something simple that I am doing all wrong? Please help, thanks!


In the first frame of my .fla:
Code:

import TheInfo;

var info:TheInfo = new TheInfo();
trace (info._theXML);


In TheInfo class:
Code:

package
{
   import flash.net.URLLoader;
   import flash.net.URLRequest;
   import flash.display.Loader;
   import flash.events.*;
   import flash.display.DisplayObject;
   
   public class TheInfo
   {
      private var _theXML:XML;;
      //var thePic:DisplayObject;
      
      public function TheInfo()
      {
         var xmlLoader:URLLoader = new URLLoader();
         var xmlReq:URLRequest = new URLRequest("info.xml");
         xmlLoader.load(xmlReq);
         xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
      }
      
      private function xmlLoaded(e:Event):void
      {
         var xml:XML= new XML(e.target.data);
         this._theXML = xml;
      }
   }
}


In info.xml:
Code:

<background>images/image.png</background>

Variables On The Fly Inside A Class-how
If we need to declare all variables in a class like

var aR:Array;

for example , then how can i avoid the error message created when i try to dynamicly create a variable within that class...


this["c"+i]=i;
trace(this.c1);

error is that c1 has not been declared. This is very helpful to create these properties within the object then i can delete them later, i dont want to create a variable on the root.

thanks
mojito

Variables And Objects In Class
Hi,
I have 2 problems:
1.
class ClassA {
private var objects:Array;
function ClassA() {
objects = new Array();
// blah blah
}

public function reset() {
trace(objects);
}
}

I cannot reach "objects" array in reset() what is the problem here?

2. in this class I create objects with createClassObject() and movieclips
but I cannot remove them. What can I do for this?

thanx

Tween Class With Variables
Hi all,
I could use a little help here. I'm trying to use values from an XML doc to get the beginning and ending values for a simple tween that changes the width and height of a box. I finally figured out how to get the values into flash, store, and use them in my tween parameters, but now the behaviour of the tween is bugging out. This maybe because I'm ussing arrays to hold the width and height data in an inappropriate way. I'm not too sure. I've attached the code and the xml doc with this message. Any help is greatly appreciated.
Thanks,
Mike

Variables Inside Class
hi,
i am creating my own component. the problem is how can i access the variables inside the Class without using _root.myComponentName.variableName.
check out the code.

class Loader extends MovieClip {
private var __maskHeight:Number = 450;

Loader(){
//create some movieClip here
movieClip.onLoad = function():Void{
//how can i access the __maskHeight variable here
//when i trace it, it shows me undefined
}
}

}

Faraz

Global Variables In Class
To my understanding global variables were accessible in classes. However when I try to use _global.myVar, 'undefined' is returned . However I discovered that if I use _root._global.myVar, then the value of the variable is returned.

I swear that _global.myVar used to work for me so an explanation of why _root._global.myVar needs to be used would be nice as it is really bugging me!

Accessing Variables From Another Class
I'm new to working with multiple classes, so be gentle. I have a doc class and one other class (Input.as). I want to access a variable from Input in my doc class. I've imported the class successfully, but can't seem to access the variable. I thought I would just need to access that var by something like Input.strNum but get this error:

1119: Access of possibly undefined property strNum through a reference with static type Class.

Defining And Using Class Variables
OK I am using Colin Moock' Flash 5 Actionscript book but even so ... in Flash 6 I'm not getting access to variables defined in the class constructor when trying to access from methods added using MyClass.prototype.newMethod = function () {...}; When I change them to instance variables ie this.variable then all works fine .... but what I really want in this case is one variable global to the class ... not one peculiar to each instance ... tried various wrinkles like using MyClass.variable ... but cannot understand why values are inaccessible / undefined as class variables but working fine as instance variables. OK maybe I should step up to MX 2004 to better OO Actionscript implementation ... can't afford to right now, though, and Studio MX is such a powerful set of tools!
Thanks in anticipation for any insight here!

Class Variables Not Accessable
hi all,
I tried to symplify the use of streaming flvs. So I wrote a class with all the stuff in it. It calls/attaches etc. the movie very well but I have one problem. I ask for the duration of the flv with the .onMetaData event (it was mentioned somewhere in the forum) which works well too.
But if I try to use class variables in the onMetaData event I cant even access one class variable - in this case I want to address nVstream. Is there a way to get this work. The current code below doesnt - as i already mentioned


Code:
class newVid {
// user set vars
var nVfile:String;
var nVtarget:MovieClip;
var nVctrl:MovieClip;
var nVbuf:Number;

// dynamically set vars
var nVdur:Number;
var nVconn:NetConnection;
var nVstream:NetStream;


public function nVinit() {
var nVint;
nVconn = new NetConnection();
nVconn.connect(null);
nVstream = new NetStream(nVconn);
nVstream.setBufferTime(nVbuf);
nVtarget.attachVideo(nVstream);

//getting duration of flv movie
nVstream.onMetaData = function(obj) {
nVdur = obj.duration;
trace("meta incoming ... "+nVdur);
nVint = setInterval(getPlayhead,1000,nVstream,nVdur);
}

nVstream.play(nVfile);

function getPlayhead(tmpStream,tmpDur) {
trace("playhead: "+nVstream.time+" / "+tmpDur);
return tmpDur;
}
}
}
thanks in advance

Problem With Class Variables
Ok i have such class:

Code:
import flash.net.FileReference;
class imgUpload{
private var imageFile:FileReference;
public var uploadURL:String;
private var listener:Object=new Object();
function imgUpload(url){
uploadURL=url;
imageFile=new FileReference();
listener.onSelect = function(selectedFile:FileReference, url):Void{
trace(uploadURL);//result is undefined
selectedFile.upload(uploadURL+"?id="+item['biblio_id']);
}
imageFile.addListener(listener);
}
function browse(itm){
imageFile.browse([{description:"Image Files", extension:"*.jpg;*.gif;*.png"}]);
}
};
i need uploadURL value in listener.onSelect = function. How to get it?
I tryed variuos ways, like this._parent.uploadURL, selectedFile._parent.uploadURL nothing work

Tween Class And Using Variables
I'm having trouble using a variable as the 1st paramenter in the Tween class.
// f2_mc is the name of the clip to be tweened
on (press) {
_global.mcName = MovieClip;
_global.mcName = f2_mc;
_root.setXposition();
}
function (setXposition) {
var moveIn:Object = new Tween(_global.mcName, "_x", Strong.easeOut, 600, 50, 2, true);
moveIn.onMotionFinished = function() {
}
}

Help With Custom Class Variables
Hi I'm trying to write my first AS 2.0 class that is basically will fade clips in and out. Here's my code:

Code:
class FadeControls extends MovieClip {
//variables
private var currentAlpha:Number;
private var finalAlpha:Number;
private var faderInterval;
private var ease:Number = .1;

//constructor
function FadeControls() {
trace("FadeControls Class loaded on "+this);
}

public function fadeTo(inputAlpha:Number):Void {
// begins the fade interval and sets initial values
currentAlpha = _alpha;
trace("current alpha: "+currentAlpha); // works
finalAlpha = inputAlpha;
// trace(finalAlpha); // also works
faderInterval = setInterval(fader, 33);
}

private function fader():Void {
trace("current alpha in fader(): "+currentAlpha); // breaks! why!?
var increment:Number;

increment = (finalAlpha-currentAlpha)*ease;
currentAlpha += increment;

_alpha = currentAlpha;

if (Math.abs(finalAlpha-currentAlpha)<=1) {
_alpha = finalAlpha;
clearInterval(faderInterval);
}
}
}
I'm having a problem with my variables coming up "undefined" when I try to use them in the fader() function. I can trace the variables "currentAlpha" and "finalAlpha" just fine within the fadeTo() function. Why do they resolve as undefined in the fader() function? I've been using Senocular's OOP tutorial on Kirupa here and can't see what makes mine break. Any help is greatly appreciated!

SetInterval And Class Variables
hi all

very recently i got to work on this thing. The behaviour is weird. if I call setInterval function from my class method it wont give me the class variables.
but when i call that function individually it works ok.

here is the code.



function fnMain()
{
this._nIndex=0;
this._nInterval=null;
}
fnMain.prototype.callBack=function()
{
this._nInterval=setInterval(this.fnFrog,200);
}
fnMain.prototype.fnFrog=function()
{
trace("index="+this._nIndex);
}
var a=new fnMain();
//---when call this it traces undefined----\
a.callBack();
//---when calling this it traces _nIndex=0--\
//a.fnFrog();


i think someone will also face this problem in past and he/she can correct me where i was wrong. Thanx for ur replies.

Class Variables In On Functions?
Hey, I was wondering if they found a better way of allowing the use of variables outside of an on function. For example in the script below I can use the variable bounds inside the target.onEnterFrame function because it's declared inside the constructer. However I can't use m_Bounds even though it's declared in the class.


ActionScript Code:
private var m_mcTarget:MovieClip;     private var m_Bounds:BoundsData;    function MotionHandler(target:MovieClip, bounds:BoundsData)    {        m_mcTarget = target;        m_Bounds = bounds;                m_mcTarget.onEnterFrame = function()        {            this._x = bounds.current.x;            this._y = bounds.current.y;        }            }


I find it annoying and unorganized to redeclare variables from my own class just to use them in the onClick/onRelease/onEnterFrame etc.

If I were to move that onEnterFrame to a different function, I would have to provide a copy of the bounds var inside that function.


ActionScript Code:
private var m_mcTarget:MovieClip;    private var m_Bounds:BoundsData;    function MotionHandler(target:MovieClip, bounds:BoundsData)    {        m_mcTarget = target;        m_Bounds = bounds;    }    public function Initialize():Void    {        var bounds:BoundsData = m_Bounds;                m_mcTarget.onEnterFrame = function()        {            this._x = bounds.current.x;            this._y = bounds.current.y;        }    }


In AS3.0 will they let us use class variables in on functions or are there any other methods?

Variables Inside Class
hi,
i am creating my own component. the problem is how can i access the variables inside the Class without using _root.myComponentName.variableName.
check out the code.

class Loader extends MovieClip {
private var __maskHeight:Number = 450;

Loader(){
//create some movieClip here
movieClip.onLoad = function():Void{
//how can i access the __maskHeight variable here
//when i trace it, it shows me undefined
}
}

}

Faraz

Variables In Class Files
Hello,
First of all, I'm sorry for posting so many dissimilar things. All of this stuff has me quite confused.

Anyway, I have a class file where I am trying to dynamically assign variables to a series of buttons. My end goal is to set up a smart navigation menu. ( Click a button & it stays highlighted..Click another button and the first button shuts off. etc. etc. )

It's kicking out a bunch of errors and I don't understand any of them. I believe I do not fully understand how variables ( public or private ) work in a class file?...among other things..I'm tryin though..

Any help would be greatly appreciated..



Code:
package classfiles{
import flash.display.MovieClip;
import flash.events.MouseEvent;
///////////////////////////
public class menu1 extends MovieClip{

public var current;
public var button1;
public var button2;


public function menu1(){
trace("Document Class Init");


button1.buttonMode = true;
button2.buttonMode = true;

button1.addEventListener(MouseEvent.CLICK, clickButton);
button1.addEventListener(MouseEvent.MOUSE_OVER, overButton);
button1.addEventListener(MouseEvent.MOUSE_OUT, outButton);
button2.addEventListener(MouseEvent.CLICK, clickButton2);
button2.addEventListener(MouseEvent.MOUSE_OVER, overButton2);
button2.addEventListener(MouseEvent.MOUSE_OUT, outButton2);

}

public function firstbutton(){
if (current != button1) {
current=button1;
trace("button 1 is on");
};
firstbutton();
// BUTTON ONE
public function clickButton(event:MouseEvent):void {
if (current != button1) {
trace("button 1 is on");
current=button1;
}
}
public function overButton(event:MouseEvent):void {
if (current != button1) {
trace("button 1 is over");
}
}
public function outButton(event:MouseEvent):void {
if (current != button1) {
trace("button 1 is out");
}
}
// BUTTON 2
public function clickButton2(event:MouseEvent):void {
if (current != button2) {
trace("button 2 is on");
current=button2;
}
}
public function overButton2(event:MouseEvent):void {
if (current != button2) {
trace("button 2 is over");
}
}
public function outButton2(event:MouseEvent):void {
if (current != button2) {
trace("button 2 is out");
}
}


////////////////////////////
}
}
}

Document Class Variables
I have a document class setting a variable called "_captioning", being set to false. I have a base class being added that needs to check and see what this variable is set to when it is added to the stage. I can't get it to read this variable at all.

I've been doing some research and found a post on this site talking about MovieClip(root) for this same problem. I can't get it to work at all. MovieClip(root)._captioning will trace from in the document class but not the base class. If I try even tracing MovieClip(root) all I get is "null". If I trace MovieClip(root) from the document class, I get [object MainEngineDocClass] (MainEngineDocClass is the name of my document class).

This thing is driving me crazy. Can anyone help?

OOP Class Variables Question
Hey

Not too long ago I started using Flash CS3 and AS3. OOP is completely new for me, but I'm getting the hang of it with time. But I have a question -

I have a class which extends a movieclip, that class is a unit. In my game, there's a player unit and an enemy unit. I'm using the same class for both, the only difference is a boolean inside that tells if it's an enemy or a player unit, which affects what array of units in the above class they should be looping and checking for foes nearby.

To create a unit, what I do, and I figured is wrong, is after creating the unit in a create unit function I have, only then I set the boolean, from the outside, for instance:
unit = new unit_mc;
unit.isPlayer = true;

So 'in the long run' it plays fine, but when I create the class first, it already run loops and ifs regarding the isPlayer boolean, which wasn't yet defined, but only a line after.

So my question is, is there a way to define a boolean from the outside in the same time of creation? If not, how else can I solve this issue?
I thought about making a class that extends Unit, that only sets the boolean (using super.isPlayer, I believe?), but is it right to work that way?

Thanks a bunch!

Access Other Class' Variables
Hello Everyone,

I am making a tileMap class which copies bitmapdata from one location to another. I am storing all my tile-sheets as static bitmapdata objects in an Assets class. Would it be faster/ better practice to copy the tile-sheet I am using to the tileMap class instead of referencing the assets class multiple times every frame? Also the map array which stores the tile reference is stored as a static property in a map class, could I achieve better performance by duplicating this array in the tileMap class?

Thanks

Spir

Class Function And Variables Within Not Visible
please help with scope issue if u can!
heres the class at fault
-----------------------------------------
class fZoomAndMove extends MovieClip {
var unblock:Boolean;
var goalX:Number
var goalY:Number
var curX:Number;
var curY:Number;
var which:MovieClip;
var scaleGoal:Number;
var diffScale:Number;
var booMove:Boolean = true;
private var booScale:Boolean = true;
private var acc:Number = 2;
private var name:String;
var doThing:Number;
//
public function fZoomAndMove(which:MovieClip, curX:Number, curY:Number, scaleGoal:Number, goalX:Number, goalY:Number, unblock:Boolean) {
trace("++"+acc);
this.name=String(which);
this.booScale=true;
trace("constructing now"+this.name);
doThing=setInterval(mov,100,this.name);
}
//create the limits based on what and where we want to move
//
private function mov (which) {
trace(">>"+this);
if (this.booScale) {
trace("scale");

diffScale = scaleGoal-which._xscale;
which._xscale += diffScale/acc;
which._yscale += diffScale/acc;
}
if (booMove) {
var diffx:Number = goalX-which._x;
var diffy:Number = goalY-which._y;
which._x += diffx/acc;
which._y += diffy/acc;
}
if (Math.floor(goalX) == Math.ceil(which._x) && Math.floor(goalY) == Math.ceil(which._y)) {
if (unblock) {
removeMovieClip(blocker);
unblock = false;
}
booMove = false;
clearInterval(doThing);
_root.fCheckFinished();
}
};
}

-----------------------------------------------------------------

the second function cannot see the variables defined before the constructor, it only sees things i pass it as attributes which is not at all handy.
what am i missing
any help greatly appreciated.

cheers
m

Is There Any Way To Access Class Variables From Linked MC?
Let's say I have a class called "Calendar" that has an MC called "buttonDisplay_mc" linked to it. Inside "buttonDisplay_mc" I have, among other buttons, "january_mc".

How would I make it so that upon "january_mc.onRelease", it sets a variable "month" inside the "Calendar" class?

Thank you very much in advance for your time.

PS:AS2 in Flash 8;

[MX04] Accesising Variables In A Class
Howdy guys and gals,

Im stuck trying to get the variables from a class I have. It's only two number variables that I need to change in my game. At the moment class is linked to movieclips by the linkage propety in the library. I'm not too sure if I have to import the class through AS or if there's a way to access it from the movieclips at are linked to it. Any feedback is greatly appreciated.

[F8] Accessing Variables In Custom Class
Yep... probably another scoping problem... but I can't figure it out.

I have a very simple script. I'm trying to pass a variable to a function and it's not working. Here is the code that exists inside the custom class:

Code:
public var myNumber:Number = 0;

public function testingVars(){

myNumber = 258;

trace(myNumber); // this works... returns 258.

myButton.onPress = function(){
trace(myNumber); // this returns "undefined".
}}
Like... why?!

Autogenerate Get And Set Functions From Class Variables
Hi all

I have created a site to ease the evelopment of good object oriented AS code. http://www.houen.net/codegenerator/index.php?language=5
You can use it to paste in your private instance variables e.g.


Code:
private var _email:String;
private var _pageCount:Number
and the server will respond with


Code:
//-------------QUERIES-------------
public function get_email():String {
return _email;
}
public function get_pageCount():Number {
return _pageCount;
}
//-------------COMMANDS------------
public function set_email(email:String) {
_email = email;
}
public function set_pageCount(pageCount:Number) {
_pageCount = pageCount;
}
Hope you find it useful

PS: It also works for C#,PHP, Java and C++ BTW

Sending Variables To Custom Class
This seems like a really simple task but I don't know how to do it.

I have a variable set inside my custom class:

var thumbLink:String;

Is there a way to set that variable from my Flash file timeline and communicate it to the class?

Accessing Variables From One Class In Another - Not Working...
Class A instantiates classes B and C. All these classes are different. Both instances of B and C know who there parent is, so can therefore access each others varaibles through the first class.

Class B has the following variable:

Code:
private var aItemArray_array:Array;
This array is populated later on in the class.

I want to access the aItemArray_array from within class C.

I tried the following:

Code:
trace(_root.instanceOf_A.instanceOf_B.aItemArray_array)
It returns as undefined.

I tried to make the variable public, that resulted in the same trace. I also set the function in class B which sets the variable to public. That didn't work either...

What am I doing wrong here?

Accessing Stage Variables From Class
hi ..

I have written some action script (well most of the script) on main time line without using any CLASS - (bad practice) .. there are many variables that i have created there and the stage objects .. I am using those objects on main time line as ..


ActionScript Code:
this.mVideo.someProperty ...

now i have written a class say .. "Test.as" which i have placed in the same directory. now while being in that class method, how can i access variables define on the timeline actionscript + on the stage ..

how can i access that "mVideo" object from that class ??

Passing Variables Between Class Files
Hi,

I have a very basic question about AS3 code setup. I have a textArea mc in my main Flash file that references an external .as class file for its scrolling (the scrolling is dependent on the text loading first in order to size the scrollbar). I am trying to pass URLs of text files to load into the textArea field from the main flash file (which contains most of my code).

could I pass something to the external file from the main one like this?
myExternalClass.someFunction(newURLvalue);

Thanks in advance for any help.

Bobby

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

Accessing Variables From A Root Class
I am working with the basics on getting accustomed to AS3 and working in classes. Normally, I use a lot of functions called up from the root. The class structure is appealing, but I am having a tough time with some of the things that I normally do. -One of which is to have a _root or _global variable to hold preferences (such as an audio toggle or volume). For storing session preferences that extend throughout the scope of a Flash site/app, these are preferred. Well...as you are aware, the _root and _global variables are no more. I have done a lot of research into this and I think I am close to a solution, but perhaps my syntax is off.



source: http://www.exade.com/temp/testGlobal.zip

On the root timeline, I call the class (works) and then trace it out (also works). According to this script, which is modified from http://www.kirupa.com/forum/showthread.php?p=2110830, I can use this to create a pseudo glo.bal variable. However, when I run the SAME trace function (that works on the main timeline) from within a movie clip -it fails. "Access of undefined property glo"

NOW, if I import the class into the movie clip and run the trace from that movie clip, -it works. However, this doesn't help because I am trying to store a variable that works across the entire scope of a file; not intiate a new instance of this variable for every timeline in the scope of a site. I want to initiate it once and change it from any timeline or script -globally.

Perhaps I am going about this all wrong. Therefore, if it can be pulled off a different way, the end is still the same. -I need a toggle switch(es) that can hold settings across ALL timelines and movie clips in a Flash file.

Thanks in advance!









Attach Code

package com.virion.as3.common{
public class glo {
public static var bal:Object = new Object();

if (glo.bal.testVar == undefined) {
glo.bal.testVar = true;
}
}
}

Sending Variables To Custom Class
This seems like a really simple task but I don't know how to do it.

I have a variable set inside my custom class:

var thumbLink:String;

Is there a way to set that variable from my Flash file timeline and communicate it to the class?

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.

Passing Variables Class And Function
ok, I'm still learning all this and can't seem to figure out when I have access to my variables. I have the the follow code:

class Slider {
var myVar = 4;


function Slider () {

var myVar = 6;
}


function findValue () {
trace (myVar);
}
}

The slider function is being called first to update the myVar value then the findValue function is called. How do I get the find Value function to output 6 ?

I want a function that updates the main classes' variable so thet I can use it from any function. Any help??

Addressing Class Variables Which Are Movies
Hello, I'm having a bit of a problem with this.

I have a class- MiniMap which extends the MovieClip class.

This class has a variable which is itself a movieClip, this movieClip is a small window which can be moved around on the map to select which portion of the miniMap will be shown in the bigger map.

How do I refer back a events on the class variables to effect the host class?

Here's some code:


Code:
dynamic class MiniMap extends MovieClip {

var myWindow:WorldWindow;
var myZoomIn:MovieClip;
var myZoomOut:MovieClip;

function MiniMap() {

this.attachMovie("WorldWindow", "myW", this.getNextHighestDepth());

myWindow = myW;
}
That's the opening of the MiniMap

Now for the world window class:


Code:
dynamic class WorldWindow extends MovieClip {

function WorldWindow() {

this._x = 10;
this._y = 10;
this._width = 80;
this._height = 50;

}

public function onPress(){
this.startDrag(false,0,0,200 - this._width, 126 - this._height);
trace("doing something");
//THIS DOES NOTHING...
}

function onRelease(){
this.stopDrag();
}

}
Any hints would be very gratefully received.

Thanks
M

Change Variables In Class With A Function...
My first post ever!

Ok, I'm building an interactive webcam thing... In a few words I try to make a color trace when you move in front of your webcam. I use different kinds of filters but mainly I want to change the variables in the ColorMatrixFilter, that's in my class.

I have also this little ball that sense if you "touch" it, a kind of motion detection. When you touch the ball I call this function. I want that function to change the variables in the ColorMatrixFilter that's in my class called "WebcamMotion". But I don't know how to do...

Here is the code for the motion detection of "ball-mc" in my fla:


Code:
var vid:Video;
var cam:Camera = Camera.get();
vid.attachVideo(cam);

//
// 2. the activityLevel property
//

this.onEnterFrame = function() {
var actLevel:Number = cam.activityLevel;
};
cam.onActivity = function(isActive:Boolean) {
};

//
// 3. The BitmapData class
//

import flash.display.BitmapData;
var screenS = new BitmapData(cam.width, cam.height);

////

var sizeDif:Number = videoW/cam.width;

var now = new BitmapData(cam.width, cam.height);
var before = new BitmapData(cam.width, cam.height);

function hitDetect() {

var ballX:Number = (ball_mc._x-videoX)/sizeDif
var ballY:Number = (ball_mc._y-videoY)/sizeDif

now.draw(vid)

var valNow:Number = (now.getPixel(ballX, ballY) >> 16 & 0xFF);
var valBefore:Number = (before.getPixel(ballX, ballY) >> 16 & 0xFF);


if (valNow>valBefore+30 || valNow<valBefore-30) {
trace ("hit")
if (ball_mc._currentframe == 1)
ball_mc.gotoAndPlay(2)
}


before.draw(vid)
}


var intervalID:Number = setInterval(hitDetect, 20);
And here is the code for the class:


Code:
class WebcamMotion extends MovieClip


{

var fireBmp, prevBmp, tempBmp, greyBmp, mtx, pnt, blurF, greyscaleCMF, fireCMF, dispMapF, webcam, createEmptyMovieClip, fireBmpHolder;

function WebcamMotion()


{

super();

fireBmp = new flash.display.BitmapData(640, 480, false, 0);

prevBmp = fireBmp.clone();

tempBmp = fireBmp.clone();

greyBmp = new flash.display.BitmapData(640, 480, false, 16743424);

mtx = new flash.geom.Matrix();

pnt = new flash.geom.Point();

blurF = new flash.filters.BlurFilter(20, 20, 10);

greyscaleCMF = new flash.filters.ColorMatrixFilter([3.300000E-001, 3.300000E-001, 3.300000E-001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]);

fireCMF = new flash.filters.ColorMatrixFilter([9.000000E-001, 2.000000E-001, 0, 0, 0, 0, 1.500000E-001, 0, 0, 0, 0, 0, 9.000000E-001, 0, 0, 0, 0, 1, 0]);

dispMapF = new flash.filters.DisplacementMapFilter(tempBmp, pnt, 40, 40, 40, -35, "wrap");




} // End of the function

function onLoad()

{

this.configUI();

} // End of the function

function configUI()

{
//webcam._visible = false;
webcam._alpha = 100;

webcam._xscale = webcam._yscale = 100;

var _loc2 = Camera.get();

webcam.vid.attachVideo(_loc2);

fireBmpHolder = this.createEmptyMovieClip("fireBmpHolder", 1);

fireBmpHolder._xscale = fireBmpHolder._yscale = 100;

fireBmpHolder.attachBitmap(fireBmp, 1, "always", false);

fireBmpHolder.blendMode = "hardlight";



} // End of the function

function onEnterFrame()

{

tempBmp.copyPixels(prevBmp, prevBmp.rectangle, pnt);

prevBmp.draw(webcam);

if (tempBmp.getPixel(1, 1) < 2)



{

return;

} // end if

tempBmp.draw(prevBmp, mtx, null, "overlay");

tempBmp.applyFilter(tempBmp, tempBmp.rectangle, pnt, greyscaleCMF);

tempBmp.threshold(tempBmp, tempBmp.rectangle, pnt, ">", 1638400, 4.289379E+009, 16711680, false);

tempBmp.applyFilter(tempBmp, tempBmp.rectangle, pnt, blurF);

fireBmp.draw(tempBmp, mtx, null, "add");

tempBmp.perlinNoise(13, 10, 1, random(100), false, true, 3, false);

tempBmp.draw(greyBmp, mtx, null, "screen");

fireBmp.applyFilter(fireBmp, fireBmp.rectangle, pnt, dispMapF);

fireBmp.applyFilter(fireBmp, fireBmp.rectangle, pnt, fireCMF);


} // End of the function

static var CLASS_REF = WebcamMotion;

static var LINKAGE_ID = "WebcamMotion";

} // End of Class
If anyone know how to solve this it would be awesome!

I post my fla and class too.

/Sewen

Is It Possible To Access Class Variables From Timeline?
Hello there
I have a document class myClass, where i set a variable:

Code:
var playhead:String = new String("");
index_menu_bar.menu_bar.btn_menu.addEventListener(MouseEvent.MOUSE_OVER, MouseOverBar);
function MouseOverBar(e:MouseEvent):void{
index_menu_bar.playhead = "hs";
index_menu_bar.play();
}
and in the timeline I have a movie clip index_menu_bar inside it, say in frame 25 I have this script hat tries to get the variable from the class

Code:
stop();
gotoAndPlay(playhead);
but i got error:

Code:
1120 : access to undifined property playhead
as you can see i already defined this property on my class!!
any clews?
thanx

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