Professional :: Accessing A Variable Defined In One Class From Another Class?

Mar 14, 2011

I've only been programming in as3 for a couple months, and so far I've written several compositional classes that take MovieClips as inputs to handle behaviors and interactions in a simple game I'm creating. One problem I keep coming upon is that I'd love to access the custom variables I define within one class from another class. In the game I'm creating, Main.as is my document class, from which I invoke a class called 'Level1.as' which invokes all the other classes I've written.Below I've pasted my class 'DieLikeThePhishes'. For example, I would love to know the syntax for accessing the boolean variable 'phish1BeenHit' (line 31) from another class. I've tried the dot syntax you would use to access a MovieClip inside another MovieClip and it doesn't seem  to be working for me

package  jab.enemy
{
import flash.display.MovieClip;

[code].....

View 1 Replies


Similar Posts:


Professional :: Accessing A Variable Defined In One Class From Another Class

Mar 14, 2011

I've only been programming in as3 for a couple months, and so far I've written several compositional classes that take MovieClips as inputs to handle behaviors and interactions in a simple game I'm creating. One problem I keep coming upon is that I'd love to access the custom variables I define within one class from another class. In the game I'm creating, Main.as is my document class, from which I invoke a class called 'Level1.as' which invokes all the other classes I've written.Below I've pasted my class 'DieLikeThePhishes'. For example, I would love to know the syntax for accessing the boolean variable 'phish1BeenHit' (line 31) from another class. I've tried the dot syntax you would use to access a MovieClip inside another MovieClip and it doesn't seem to be working for me.[code]

View 1 Replies

ActionScript 3.0 :: Accessing A Class's Static Functions From A Variable Of Type Class?

Feb 19, 2010

I realize this is kind of an odd issue, but I am wondering if there's any way to get Flash to allow me to access a class's static functions using a class variable that points to the class. Example:I create a class called FooClass that has a static function named fooI then create a variable of type Class that points to it

Code:
var class:Class = Class(getDefinitionByName("FooClass"));
However, when I try to call foo() using the variable, it errors saying the function

[code].....

View 6 Replies

ActionScript 3.0 :: Accessing Variable In Document Class From Within Another Class?

Mar 11, 2009

I have an array in my doc class that I'd like to access from an external class. Can you do this and if so what's the syntax?

View 6 Replies

ActionScript 3.0 :: Accessing A Variable Name Containing A Class From The Class Itself?

Jul 21, 2010

would it be possible to access a variable name containing a class from the class itself?

Example:
Code:
var __NAME__ = new TestClass();
package com.Test
{

[Code]...

View 14 Replies

Professional :: Accessing Timeline From Class Loaded Into Doc Class?

Jun 12, 2011

I can't find a way to directly access a MC (or textfield, etc) on the timeline from a Class loaded into my Document Class. No problem from the Doc Class, but can't do it directly from the loaded Class. Is there a trick to essentiall extend the Doc Class AS from another external class?

View 7 Replies

ActionScript 3 :: Instantiate Class From String - Variable Not Defined

Aug 3, 2011

I've got a string which, in run-time, contains the name of a class that I want to instantiate. I read suggestions to use
flash.utils.getDefinitionByName():
var myClass:Class = getDefinitionByName("package.className") as Class;
var myInstance:* = new myClass();

However, that gives me the following error:
[Fault] exception, information=ReferenceError: Error #1065: Variable className is not defined.

View 1 Replies

ActionScript 3 :: Variable Flash UI - MouseCursor Class Not Defined

Jan 16, 2012

This is quite strange to me since the MouseCursor class is being used as static.
Mouse.cursor = MouseCursor.BUTTON;
This is what I am using the MouseCursor class as and hence it is static. We got this error posted by a customer and the customer has also attached a screenshot of the error.
ReferenceError: Error #1065: Variable flash.ui::MouseCursor is not defined
I first assumed that this could be perhaps because he was running an older version of Flash Player ( older than v10 ). But his screenshot clearly shows that it is running version 10 of the flash player.

View 2 Replies

ActionScript 3.0 :: ReferenceError: Error #1065: Variable <Class> Is Not Defined??

Mar 3, 2009

I have been trying to migrate a CS3 based Flash project to the new CS4 IDE for some days, but it has been impossible. All the conponents of the library throw the same error at building time:

ReferenceError: Error #1065: Variable <Class> is not defined.I have changed the name of all clases with the same name as
the package,

I have also changed the name of the main class.I have created a new empty .fla to copy and paste all the elements of the library,BUT I DO NOT STILL GET TO SOLVE THE PROBLEM.

View 11 Replies

Actionscript 3 :: Calling A Method, Which Is Defined In Another Class, From Main Class Gives Error 1120?

Aug 16, 2010

I have two classes. The Main class calls a function, which is defined in a Second class.I'm getting the following error:Error 1120: Access of undefined property myFunctionBasically, I am creating buttons in the Main class that will add a corresponding Child to an Object in the Second class (if you click one button, child x1 will be added, if you click another button, child x2 will be added, and so forth).Here's the relevant code for the Main.as file:

package
{
import flash.display.MovieClip;

[code].....

View 3 Replies

ActionScript 3.0 :: 1061 Error (not Defined) When Call A Method Of A Self Defined Class

Feb 9, 2010

I am using flex builder 3.2, Action Script 3 and develop for Flash Player 10 and am quite new to it. when I call a method of a self defined class, I get the 1061 error (not defined). But the class and the method exist and are public, so what the hell am I doing wrong? Flash Builder is even offering me this method in the auto-completion, so at least the builder knows it... I have already tried cleaning the project (as this is the common source of strange errors when working with java/eclipse),

edit: solved... The problem was that a package had the same name as the variable I used for the class. Very strange error message, thumbs down for this .

View 0 Replies

ActionScript 3.0 :: Accessing Variable From Another Class?

Jan 4, 2011

I'm having trouble setting up my Ball class so I can set a variable which I can then access in another class later. I'm under the impression you can only do this with a public static var, but when I try to make my variable public static the code doesn't work.

[Code].....

the code checks where the balls are on the screen and moves them onto the square. I want to set a string variable for the direction its moving eg. "right" for the ball that's moving right. I'm not sure how to access this in another class.

View 1 Replies

ActionScript 3.0 :: Accessing Variable From Another Class

Jan 4, 2011

I'm having trouble setting up my Ball class so I can set a variable which I can then access in another class later. I'm under the impression you can only do this with a public static var, but when I try to make my variable public static the code doesn't work.

Code:
Select allpackage {
import flash.display.MovieClip;
import flash.events.Event;
public class Ball extends MovieClip {
public var _startX:uint;
public var _startY:uint;
[Code] .....

The code checks where the balls are on the screen and moves them onto the square. I want to set a string variable for the direction its moving eg. "right" for the ball that's moving right. I'm not sure how to access this in another class. Here is a pic of the screen to visualize.

View 1 Replies

ActionScript 3.0 :: Private Variable In Class - Accessing Array?

Apr 9, 2011

I have a class that creates an array from a config xml file. I set a private variable in that class and use a getter in other classes to access the array. The routine that uses the array does the following:
- Call the getter and assign the returned value to a local (private) variable tmpArray.  the getter is a simple return() using a value that is established in the constructor.
- Uses a for loop to itterate over the contents
- Uses array.shift() to pop the item in tmpArray

The next time I run the routine, the contents of the array is empty. I'm using the same getter. I implemented the getter when I tried to manage both arrays in the same class figuring that as long as the original array was private (i also tried static), that the value would not change. I have since worked around the problem by moving the routine that fills up the original value from the constructor to the getter. So, consider the following code:

import flash.events.Event;
btn.addEventListener("click", btnHandler);
var myArray = new Array();
var myTmpArray = new Array()
myArray = ["one", "two", "three"];
myTmpArray = myArray;
function btnHandler(evt:Event) {
[Code] .....

If I create a variable myVar and set it to 1 then set myOtherVar = myVar, the both equal the same value. If I change the value of myOtherVar, myVar is not affected. But using the shift() method changes both the original and the copied array.

View 5 Replies

Arrays :: Accessing Variable From Other Class Returns Null

May 10, 2011

I did a separate levelData class to be able to flexibly add levels. I was happy with it until my supervisor ordered me to convert my levelData into XML. I did an XML version of the levelData's data (question, answers, correct answer...). I used the old class and converted it so that it fetches the XML.

All seems well, I did traces of my answers array and it printed nicely...

But the headache started when I tried this.

// This code appears in a different class with
// currentLvl:LevelData initialized in the constructor.
quizHolder.ansA.ansHud.text = currentLvl.choices[1];

[Code].....

LevelData Class in PasteBin: [URL]

View 2 Replies

Flash :: Accessing A Variable Declared In Fla From Document Class?

May 24, 2011

On the stage I have a movieclip by the name of rect_mc. Inside it have have a MovieClip square_mc.In the time line that I get when I double click on rect_mc (timeline of rect_mc) I have written the following code

var width1:Number;
width1 = sqaure_mc.width;

How can I access width1 from the document class?The thing that I want to is access the variable declared (width1) in the timeline of rect_mc. Just for the sake of a example only I choose the width of MovieClip.My doubt is how can access a variable declared inside the timeline of rect_mc from the document class. It could be any variable.My document class is:

package
{
import flash.display.MovieClip[code]....

View 1 Replies

Flash :: Sending Variable From Fla To Document Class And Then Accessing?

May 31, 2011

I want to find out whether my swf was loaded locally or from another swf. For this purpose I have declared a variable 'parentType' in my fla. var parentType:String = String(parent); There is a function in the document class that determines whether swf was loaded locally or from another swf. The name of the function in the document class is 'externalOrInternal'. The varaible parentType is passed as a parameter to the function externalOrInternal externalOrInternal(parentType); The name of the document class is Main. In the constructor of Main I have the function pollResize() (the use of this function is to listen for the resizing event. That part of the code is not shown in the snippet given below).

[Code]...

I see that swfParentType is has value insde the function externalOrInternal. My doubt is why null is traced inside the function pollResize. Why is it not [object Stage] as inside externalOrInternal. Due to this I am not able proceed further with the stage resizing event.What needs to be done so that proper value is traced in the function pollResize.

View 1 Replies

ActionScript 3.0 :: Accessing Document Custom Class Variable

Jun 15, 2010

I've made a custom sound class:
ActionScript Code:
package {
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
[Code] .....
What I would like that class do is to trace a variable that is on Main.as which is Document Class, after a sound completed playing.

View 4 Replies

ActionScript 2.0 :: Accessing Main Timeline Variable From Within A Class?

Dec 20, 2010

I have a class, the relevant parts of which are defined as follows:

class myClass extends MovieClip {
public function myfunc() {
trace( "mainVar: " + _root.mainVar );
}
}

As you can see, I want to access the variable "mainVar", which exists in the main movie, from within the class. This works fine, if I have only one instance of the class. But, if I have more than one instance, within separate movie clips, the value of mainVar is always taken from the first instance. How do I refer to the actual instance from within the class?

View 0 Replies

ActionScript 3.0 :: Accessing A Class Variable In The Main Timeline?

Jun 2, 2011

Here's my main class:

Code:
package
{
import flash.external.ExternalInterface;

[Code]....

Basically the class waits for the callback variable (my_msg). The problem is: I need to set the dynamic textbox text to my_msg variable.

How can I access it? I know I can access a public var in the timeline with functioname.variable but I can't define a public var inside a function, right?

View 4 Replies

ActionScript 3.0 :: Accessing A Main Timeline Variable From A Class?

May 18, 2010

I'm was getting good with as2 but recently made the mind switch from, I'll learn as3 tomorrow to as3 is awesome. The problem for me is that I don't understand the scope for classes. I know I can trace a variable on the main time line when the var is declared in the class. But how do you access a main time line var from a class? Here's an example - main time line Monkey.fla

Code:
var cagedMonkies:int = 10;
var monkeyTransport:MovieClip = new CarTrunk();

[Code]....

View 13 Replies

ActionScript 3.0 :: Accessing A Class Private Variable In The Main Timeline?

Jun 2, 2011

Here's my main class:
 
[code]...
 
in the timeline I have a dynamic text box named my_textbox: var my_test:main = new main(); my_test.check_DVBViewer(); my_textbox.text = ??Basically the class waits for the callback variable (my_msg). The problem is: I need to set the dynamic textbox text to my_msg variable. How can I access it? I know I can access a public var in the timeline with functioname.variable but I can't define a public var inside a function, right?

View 3 Replies

Professional :: Accessing External Class To Set In TextField

Jun 11, 2011

I'm new to AS3 and I'm trying to load a data from a XML file ("AppData") and set the data (text) in a dynamic text field("Label") on the stage. For accessing and manipulating the XML file ,I have an external as file with a class called "DataClass". And I running scripts in project frame to access the data from XML in the class "DataClass" to set it in the text field.

View 2 Replies

ActionScript 3.0 :: Accessing An Object Drawn On The Stage In One Class From Another Class

Jan 6, 2011

I have created a class, call it Class1, that has various objects drawn on the stage (drawn in the IDE). It also has a function, called setColour, for changing the colour of those objects. The function works fine if I call it from within Class1.

Now I have another class, call it testClass1, that imports Class1 and calls the setColour function. First of all, none of the stage objects from Class1 are visible. Secondly, when setColour tries to modify the colour of an object, I get the error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

This is the code for testClass1:

ActionScript Code:
package
{
import flash.display.*;

[Code].....

So, what is the problem? Is it possible to change objects that are drawn on the stage of an imported class?

View 3 Replies

Professional :: Accessing Class Instance At Root From Movieclip?

Feb 25, 2010

I have declared a object in my 1 st frame of application.

ActionScript Code:
var objTest:Test = new Test();

I am tring to access the object from a movie clip. Movie clip is located in frame 2. I am getting error

ActionScript Code:
this.parent.objTest.IncrementCount();
trace(this.parent.objTest.QuestionCount);

[code].....

View 4 Replies

ActionScript 3.0 :: Accessing Properties Of A Member Of A Class From Within The Class?

Jun 9, 2011

I have a class, call it MyClass, and there are several variables that I need to be able to access each instance of from within the class.So for instance, I need the object myObject1, a member of MyClass, to store the variable myNumber.From the main timeline, if I trace myObject1.myNumber, I get whatever number I've stored.
 
However, I need to check the numbers against another parameter, so I need to be able to test if myObject.myNumber == myOtherNumber. But from within the class, if I trace this.myNumber or myNumber I get null.What is the proper syntax for accessing a variable within a class?

View 5 Replies

ActionScript 3.0 :: Accessing The Stage From A Class Which Isn't The Document Class?

Jul 3, 2009

I'm being really dumb today and I know this should be simple.....How do i access the stage from a class which isn't the Document Class? For instance, I want to create a tween which takes in the parameters of the stage's width? So I've written.....

ActionScript Code:
var myTweenX:Tween = new Tween(this, "x", Regular.easeOut, this.x, stage.stageWidth, 60, true);

[code].....

View 4 Replies

ActionScript 3.0 :: Accessing A Class Property Through Document Class?

Sep 3, 2009

I have a document class that looks like this:

Code:
package
{
import Map;

[Code]....

Is it possible to access a property of the Map class (though map defined in the Document class) from within the hero class?

View 4 Replies

ActionScript 3.0 :: Accessing Document Class Property From Another Class

Feb 28, 2010

The Main.as file will have all of the game logic, such as the mysteryNumber.

The other actionScript files represent rooms that the user may click and depending on the 'mysteryNumber', it will execute the 1 of 6 scenarios.

So for example, if a user clicks the Library page, the LibPage.as will call the 'mysteryNumber' and execute some code to display on the library page.

It will be the same for the other 4 rooms.

The problem I have is that the LibPage.as won't call the 'theNumber' property from Main.as

Here's the Main.as

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

[Code]....

View 3 Replies

ActionScript 3.0 :: Accessing Function On Sub Class Via Default Class

Oct 6, 2010

I'm trying to do this,

Code:
Main.instance.subClassFunction();

instance is a public static variable on the default class, Main. I can do Main.instance.defaultClassFunction() with no problems at all, I use it to access functions and variables from within other classes. Is it possible to use this method to call a function on the subclass, currently I have to do this,

[Code]...

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved