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


Similar Posts:


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 :: Dynamically Referencing Movieclips?

Nov 28, 2011

I'd like to know how I can achieve this in AS3. The code would work fine in AS2, but as I am very new to AS3 I am not sure what the equivalent would be in AS3.

code:
humanNum = 1;
MC = ["Human"+humanNum];

[code].....

View 1 Replies

ActionScript 3.0 :: Referencing Movieclips On Different Frames?

Jul 9, 2009

I have a main fla with loaded swfs. I would like that I can access a movie clip
in a swf from from another swf.

I would like a button on one frame, when clicked, to go to another frame of a movie clip in a loaded swf on a different frame.

View 6 Replies

ActionScript 3.0 :: Referencing MovieClips Made From The UI?

Aug 26, 2009

I have 23 movieclips on Stage. Each one is a class of 'point', and has been given an instance name of p1, p2, p3, p4 etc.I want to reference them in code, and then get their x and y co-ords eventually.How do I make them accessible variables in AS3? in AS2 I would have put them into a for loop, and said

Code:
for(i=0,i<23;i++)
{

[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 3.0 :: Referencing Movieclips To The Stage Or Root

Jun 18, 2009

I have a movieclip "submenu" that is on the main timeline, and inside this movieclip, I have some ActionScript:

[Code]....

View 3 Replies

ActionScript 3.0 :: Dynamically Referencing Movieclips On The Stage?

Jan 20, 2011

Just wondering, is there any way to dynamically reference movieclips on the stage, as in through a for loop like so:

for (var i = 0; i < 10; i++) {
["mc" + i].x = 10;
}

[code]........

View 3 Replies

Actionscript 3.0 :: Referencing Movieclips Inside An Array?

Dec 16, 2010

I am trying to reference a movieclip located inside an array to add an eventlistener and function... I am using array[0].add...ect. The code for the first movie clip works, but for the rest I get an error 1010.

Code: Select allvar image:MovieClip = new Image();
addChild(image);
const MAX_ITEMS:uint = 6;

[code].....

View 1 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 2.0 :: [MX04] Referencing Multiple Movieclips With Single Variable?

Jan 25, 2009

Is there a way to reference multiple movieclips using a single variable name? For example,I'm making a side-scrolling game, and there's going to be many platforms, and I have some code that tells the player not to fall through these platforms, but I don't want to copy and paste the same "platform" code every time I add a new platform.

View 3 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 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

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

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

ActionScript 3.0 :: Referencing A Dynamic Textfield From A Class

May 25, 2010

how do I reference a dynamic text field in my fla file from a class which isn't the document class? For example: I have an fla file called main.fla which contains no actionscript and has a single dynamic textfield called "text_txt" on the main timeline.

[Code]....

View 8 Replies

Flex :: MXML Class Referencing Syntax?

Mar 17, 2011

I'm having a problem that has been really getting to me for the last 12 hours or so and I can't seem to find the answer anywhere. I know it's something simple, but I just don't know the correct syntax.

I've got a Flex Application in Flash Builder 4 with a file called "Test.mxml" which looks like this (simplified):

[Code]...

View 1 Replies

ActionScript 3.0 :: Referencing Stage.stageWidth From A Class

Jan 7, 2009

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.

[Code]....

View 3 Replies

ActionScript 3.0 :: Referencing Stage From External Class

Feb 14, 2009

I'm having problems referencing the stage from an external class. I've tried :
Code:
stage.addEventListener(MouseEvent.MOUSE_UP, onUp, false,0,true);
And also
Code:
MovieClip(parent).addEventListener(MouseEvent.MOUSE_DOWN, onDown, false,0,true);
But no luck. Can I not do this? I'm making a pencil class that I want to be able to reuse. I also tried "this" and while it didn't throw and error, it didn't work either.

View 9 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







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