ActionScript 3.0 :: Referencing Class Variables For A Movieclip?

Dec 5, 2011

Hey guys. It's been a while since I've used Flash and I am still trying to wrap my head around Actionscript 3.0 and the way it works; I am so used to the way AS2 works.I have provided the code below, it's very simple, so you might be able to skip this explanation and just take a look at the error and the code:

- I have made a movieclip called HeroMC in my FLA.

- The HeroMC movieclip has the AS Class linkage of exactly the same name, "HeroMC".

- I have made an actionscript class file, HeroMC.as, to house specific variables for my hero; such as Name, Age, xPos and yPos.

- I have also made an actionscript class file, Main.as, the document class for this FLA.

- In Main.as I instantiate HeroMC using the variable hero, and then run the function addHero() from my constructor.

- addHero() is a simple stage.addChild(hero);

This all works perfectly fine and it adds my hero to the stage. However, the problem arises whenever I try to reference one of the variables from HeroMC.as. I am met with this error - I will use the variable xPos as an example.

Here is the error:

1119: Access of possibly undefined property xPos through a reference with static type HeroMC.

Here is the code for Main.as:

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

[code]....

It is obvious this is a very simple problem, but I have searched Google, Kirupa and Flashkit for an answer, but none of the threads I find discuss my specific circumstances and I am unable to find the specific information I need to.

View 3 Replies


Similar Posts:


Flex :: Referencing Class Variables?

May 3, 2011

I have a bunch of variables in a class. There are situations when I want to set then to null/ "temp" etc as per a well defined logic. The challenge is to list out the variables at multiple places- tedious and error-prone.

classname.speed=NaN
classname.speedtype="not_set"
classname.distance=NaN
classname.distancetype="not_set"

would prefer a way to refer to these variables programatically and set something like "for all class variables- if variable ends in type, set as "not_set"; for other variables set as NaN How can I achieve this?

View 2 Replies

ActionScript 3.0 :: Referencing A MovieClip Based On Variables

Mar 15, 2012

I am having trouble referencing a MovieClip based on certain variables in my code. I am using Flash Player 9 as the player setting and ActionScript 3.

I have a symbol with a name "Check1" set as a MovieClip, exported for ActionScript, I have ten of these on the stage with an Instance Name of ch0, ch1, ch2...ch9.

Each ch? has 21 frames on the timeline, each with a label name (named with a Number reference "00", "32", etc...) and a different image in each keyframe.

What I would like to do based on these variables:

Code:
iTurn = 1;
iLeft = 3;
iRight = 2;

This is how I would like to use it:

Code:
Check1.ch[iTurn].gotoAndStop(iLeft+iRight);

//iLeft & iRight as a frame label and not a frame number, so in the case I would like to access framelabel "32" which is frame 10 on the timeline.

I have tried many way to try and make this work with no luck, the only way I have been able to make it work is by using:

Code:
ch1.gotoAndStop("32");

Doing this, I would have 10 clips, each with 21 possibilities. I can do this with many lines of code but I have been unable to tighten it into smaller code.

View 5 Replies

ActionScript 3.0 :: Referencing A Textfield Inside A Movieclip Class From Document Class

Feb 3, 2009

Ok, this is one of those walls that I know once I can jump over it, I will be a much happier developer again.

I've done tons of reading, and think I have a firm understanding that the general consensus is that if you want to reference something, it needs to be added to the display list, using addChild().

I hate to be defiant, but what if I don't want to?

Or at the very least, what if I want to add a movieclip class to the stage using addChild, and then reference objects inside it?

It is much easier this way than what most people recommend - adding 15 objects via addChild, then setting the x and y for the, etc.

That said, I'm all about using classes and using as3 the way it was meant to be used. So what this is, is a best practices question I guess.

HERE ARE THE STEPS I'M TRYING:

- Create new flash document

- Draw graphic symbol bg, with text field over it, select them, convert to movieclip symbol, and export class name "box", then delete it from stage

- Add document class .as file, which simply adds that class "box" from the library, to the display list using a simple addChild()

- Set a name for that box using box.name = "test" let's say

- Do a simple trace like the following - "getChildByName('test').textFieldName" - it shows up great

- So then, I'll now try to set the text by doing this - getChildByName('test').textFieldName.text = "yo";

That last line above, is what doesn't work. I know I'm referencing wrong, but how would a pro as3 developer, reference something on the stage within a movieclip class, from the document class?

View 1 Replies

ActionScript 3.0 :: Referencing Stage From Within MovieClip Or Class

Dec 9, 2009

I'd like to know how I can reference root stage values from within a movieclip, or even worse, from a class. For example, I have a class called Bground.as. It does stuff, according to current stage size - so if someone were to resize the window/browser, Background updates in real time and does something fancy while it's at it. To do this "fancyness", I need stageheight and stagewidth. However, simply pointing to them does not work.

Here's the simplified ActionScript Code:
package klaseFP{
// imports
import flash.events.*;
import flash.display.*;
public class Bground extends MovieClip{
[Code] .....

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at klaseFP::Bground()
at FullScreen_03_fla::MainTimeline/frame1()

Background works as a document class, works perfectly in fact. However, if I use it as the class of a library object, error 1009 shows up. Same thing happens if I simply put the code into the timeline of the library object - stage referencing simply causes it to break. So, how do I dynamically change the values of variables in Background, according to values in the main movie/app?

View 2 Replies

Actionscript 3 :: Referencing A Document Class From A Child MovieClip?

Apr 13, 2010

I have a document class with a child MovieClip on the stage. I have the clip already on the stage because it's part of an complex layout provided by the designer and it seems easier to leave it on the stage than to use addChild (since I would have to add about 60 objects).What is the best way to reference the document class from inside the child MovieClip class?

View 1 Replies

ActionScript 2.0 :: Accessing Variables In MovieClip From A Class

Feb 16, 2006

I'm writing a little application to run a course, and the engine creates the navigation menu putting labels in the button etc...

So, as far as I change things like a dynamic text that's on the stage with something like

mybutton.itemText.text = my_xml.childNodes[0].childNodes[index-1].attributes["Label"];

this works, but what If I want to change a variable declared in the button?

I would like to retrieve from an XML the movie I want to load pressing this particular button, but seems like the scope of the "designed" objects and the programmed object is a little different, since with

[Code]....

I've included a simplified version of the interface, the classes and the code is not 100% functional...

View 4 Replies

ActionScript 3.0 :: Calling Document Class Variables In A Movieclip

Feb 25, 2010

I have a variable, we'll call it helloNurse, defined in the document class, we'll call it Joy, as a public variable. Meanwhile, I have a movieclip within the FLA that uses that class as its document class that, simply put, needs to access that variable. I had read up that the following SHOULD work:

[Code]...

View 12 Replies

Actionscript 3 :: Referencing Variable In Document Class From Another Class?

Mar 11, 2011

I need to increment an integer variable in a function within the document class upon transpiring event in another class. I can't seem to figure out how to call the function and reference the variable.

View 2 Replies

ActionScript 2.0 :: Flash8 Referencing MovieClips With Variables

Jun 12, 2009

I want to reference clip with some variable name because i want to change dynamicaly target clip. Example:

myMC="testClip";
myMC.my_txt="some text";//this doesn't work
//but this works
eval(myMC).my_txt="some text";

I guess eval() is not right thing to do.

View 4 Replies

ActionScript 2.0 :: Referencing Dynamically Created Variables?

Dec 9, 2006

I have a number of 'TweenField' instances created in a for loop. The problem is that each time the loop increments, the 'myTweenField' variable has the same name, so I don't know how they can be referenced individually from elsewhere in the script. How can I rewrite it so that each instance has a unique name, and how would I then reference it from outside the loop?

Code:
package
{

[code].....

View 11 Replies

ActionScript 2.0 :: Referencing Variables In A Loaded Movie?

Sep 22, 2003

I'm having trouble referencing variables in a loaded movie. I read in other posts that you simply refer to the variable as if it belongs to the clip you load it into, however this doesn't seem to be working for me

View 2 Replies

ActionScript 3.0 :: Referencing Class Objects From Class?

Jun 19, 2010

I have an enemy on the stage that reads whether it's being hit by a bullet by a hittest. There's a for loop inside the enemy's class that looks for all the bullets and names the bullet that's hitting it "hitBullet". What I'd like to do have an easy way of seeing what type of bullet is hitting the enemy. I'm basically looking for something like

if (hitBullet == RegBullet) {
//do regular bullet dying
}else if (hitBullet == ClusterBullet) {
//do clusterbullet dying
}

, where RegBullet and ClusterBullet are classes. But I have no idea what hitBullet is equal to when a ClusterBullet or RegBullet hits it. I traced hitBullet to see what it would return and got "[object ClusterBullet]", but I'm not sure what that would be in the actual code.

View 2 Replies

ActionScript 3.0 :: Referencing Variables/objects From External FLA Files?

Dec 1, 2010

I am trying to display in 'Reciever.swf' the value a shared object updated in 'TextSO.swf'. The following is my code for the Reciever

Reciever.as-----------------
package {
import flash.events.SyncEvent; import flash.events.NetStatusEvent; import flash.events.MouseEvent; import flash.net.SharedObject; import

[Code]....

I am getting an error that says that 'text_so' is an undefined property and that I can't access it. Yes, I have not declared 'text_so' in 'Reciever.as'. However it is the shared object instance from the 'Text_SO.as' file. How do I reference it from the 'Reciever.as' so that I won't get this error anymore?

View 1 Replies

Flash :: Referencing Static Variables From Frame Scripts?

Oct 27, 2009

Got some external classes, say MyClass.as MyClass.as has a static variable called foo

So, ordinarily in other AS files I can call this with MyClass.foo = bar;

However, this seems to be different in timeline scripts. Every time I try this I get the reference with a static type error 1119: Access of possibly undefined property foo through a reference with static type flash.display:DisplayObjectContainer.

I've tried doing an import MyClass, etc... nothing seems to be firing.

View 1 Replies

ActionScript 3.0 :: Referencing Variables / Objects From External FLA Files?

Dec 1, 2010

I am trying to display in 'Reciever.swf' the value a shared object updated in 'TextSO.swf' . The following is my code for the Reciever[code].,...

I am getting an error that says that 'text_so' is an undefined property and that I can't access it. Yes, I have not declared 'text_so' in 'Reciever.as'. However it is the shared object instance from the 'Text_SO.as' file. How do I reference it from the 'Reciever.as' so that I won't get this error anymore?

View 4 Replies

ActionScript 3.0 :: Referencing To A Class From Another Class?

Sep 27, 2009

I have a class called Circle and a class called ShapeFade, both with their own .as files. How do I add an instance of ShapeFade to Circle inside the Circle constructor? Like in the Circle file:

PHP Code:

public function Circle () {
this.addChild (ShapeFade);
}

Also, can I override a class function from the code window in the stage?

View 6 Replies

ActionScript 2.0 :: Referencing A Movieclip Within An Attached Movieclip?

Nov 29, 2006

I am trying to reference a movieclip within a movieclip that I am loading using "attachmovie". In the first frame of the root, I am attaching the movie. Then, from the attached movie I am calling a function that is also in the first frame of the root. In the function I am tring to set the property of a clip within the attached movie to visible using the following code:

_root.logIn.loginMessage._visible = true;

I have also tried _root["logIn"].loginMessage._visible = true; with no luck.

(logIn is the name of the clip I am attaching using attachMovie and loginMessage is the clip I am trying to reference in the attached movie)

This is how I'm loading it and I know that part is working: _root.attachMovie("login_mc","logIn",getNextHighes tDepth());

View 1 Replies

ActionScript 3.0 :: Referencing A Library Class?

Mar 17, 2009

In As 2 you were able to reference a linkage ID using a string.Example

Code:
var strName = 'home';
attachMovie(strName+'_mc', strName, 1);

[code].....

View 3 Replies

ActionScript 3.0 :: Referencing Parent When It Could Be Of Any Class

Nov 17, 2010

I usually would call the parent of my class by something like:
MyCustomClass1(parent).thisFunction();
My problem is this works if I know the class of my parent. How do you handle the case where you class could have a parent of 2 or more possibilities?
parent.thisFunction(); // throws error of course

View 3 Replies

ActionScript 3.0 :: Referencing Parent Class?

Mar 16, 2009

A have two classes: Main and Navigation. I try to referenceobject in Main class from Navigation class based on the buttonnumber I clicked. Doesn't work as I want it to work. What can I do

View 1 Replies

Referencing Other Movieclips Within Actionscript Class

Jan 17, 2010

I have externalized the actionscript code of a movieclip into a separate class files.This movieclip requires references to some other clips on the stage. What I am currently doing to reference those clips is by using Movieclip(this.parent).otherclip but somehow that feels wrong.Is there a better way to pass in the required references into a class extending from Movieclip inside of the constructor? Or what is the recommended pattern here?

View 2 Replies

Android :: AS3 Referencing Class From Timeline

Dec 10, 2011

I can import other classes to the timeline and use them just fine, but this class is giving me major problems? I am parsing XML data from my server on it and it is giving me errors that look like this.

The timeline reference and usage:
import networkScores;
var network:networkScores = new networkScores();
addChild(network);
score1Textfield.text = network.score1.toString();
[Code] .....

The errors I am getting:
Scene 1, Layer 'Actions', Frame 4, Line 149 1119: Access of possibly undefined property score1 through a reference with static type networkScores.
1067: Implicit coercion of a value of type networkScores to an unrelated type flash.display:DisplayObject.

View 1 Replies

ActionScript 3.0 :: Referencing A Class From A SQL Table?

Mar 5, 2011

I'm working on a game that pulls most of its information from an SQL table. The game itself has several different items that derive from a BaseItem class, and all have widely varying behaviors. While deriving these classes from the BaseItem class and scripting the correct behavior is easy enough, I'm having a bit of trouble trying to come up with an efficient way of storing the information for these items so that not only will the items be in the state that the user left them when they were last saved to the database, but they will be the correct item when loaded from the database in the first place. I'd like to do this with as little pollution of the iteminfo table as possible (for instance, I want a Truck item to have a "wheels" value of 4, but I don't want an item_wheels field on the row if the item is Pogo-stick).

So far, my best idea has been giving iteminfo an "itemtype" field that accepts an enumeration, like ITEM_TRUCK or ITEM_POGOSTICK, and using a switch statement in AS3 to instantiate the correct item based on the pulled value, but this seems rather sloppy.

The thread title says that I want to reference a class directly from a table, but if I knew how to fix this I'd have done so already, so I'd love to hear any solutions. And just for the info: I'm working with a combination of AS3, PHP, and MySQL.

View 3 Replies

ActionScript 3.0 :: Referencing A Class Using A String?

Aug 10, 2011

Is it possible to use a class name stored in a string and pass it as a parameter??I'm using the push method in a flex mobile project. I have the name of the view I would like to pass into the push method stored in a string. But the push method only accepts it as a class not a string.How do I use a String to load or pass the class name to the method?

var NameClass:Class = "views.Contact";
navigator.pushView(NameClass);

View 9 Replies

ActionScript 3.0 :: Referencing All Children Of A Class?

Oct 31, 2010

just thinking out the setup of a sidescroll/platformer..i want the player not to fall through the floor or go through walls i know how to hittest with a single object, but what i have is various objects that extend the class wall. if I hittest with wall will that also apply to the serrated_floor and portcullis classes that extend wall?

View 1 Replies

ActionScript 3.0 :: Referencing A Loaded Clips Class?

Mar 18, 2009

I have a swf that is loaded into my main swf with the loader class. When I click a button in the main swf I want to call a function in the loaded swf Main class.

When I do a trace it is showing the loaded clip as [object Home] which is the name of the Main document class associated to the loaded swf. I have a public function in my Home.as called startAnimation() but when I try to call it I get

[quote]1061: 1061: Call to a possibly undefined method startAnimation through a reference with static type flash.display:Sprite.

View 21 Replies

ActionScript 3.0 :: Referencing Stage Objects From Within Class

Sep 3, 2009

How to access stage elements from within a class.
buttonControls.as

Code:
package {
import flash.display.Sprite;
public class buttonControls extends Sprite {
// Navigation Hover Color
var hover = "0xF1E960";
var normal = "0xFFFFFF";
public function changeColor(object, color){
[Code] .....

View 2 Replies

ActionScript 3.0 :: Referencing An Object Inside A Class

Feb 1, 2009

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

objGroup.obj0.addEventListener(MouseEvent.CLICK, onClick)
private function onClick (event:MouseEvent):void{
trace ("Click");
}

View 17 Replies

ActionScript 3.0 :: Referencing Movie Clips On A Class?

May 7, 2010

I'm developing a Hygrometer in Flash CS4. The Hygrometer is a Movie Clip currently on the stage with 16 Movie Clips inside with instance names like segment01_mc, segment02_mc.. segment16_mc. I'm trying to make a class for the Hygrometer MC and I need to access the "segment" MC's. But I can't find a solution.

Is there any way to reference the "segment" movie clips? How can I assign instance names to the "segment" movie clips?

Here's my current Hygrometer class code:

[Code]....

View 14 Replies







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