ActionScript 3.0 :: TextField On Stage Not Accessible In MovieClip Class
Dec 27, 2011How can I achieve this ? I tried
MovieClip(root),
MovieClip(parent),
stage,mytextfield.text = ... etc.
They all throw an null object reference problem.
How can I achieve this ? I tried
MovieClip(root),
MovieClip(parent),
stage,mytextfield.text = ... etc.
They all throw an null object reference problem.
I am trying to make a class that extends the movie clip class. I want to essentially have a movie clip class that has a "handle" by which I mean a settable reg point by referring to a parent container movie clip. I have many parts of it working. I have functions that can move the handle/parent to any location on the screen, one that centers, and a move method that moves the movie clip by moving the parent so it is being moved by the origin you specify etc.
But one thing I would like to have the handledMovieClip class to do is to make the handled movie clip and then automatically generate the parent movie clip with the same name appended with "h" and put the handledMovieClip into the parent MovieClip. The parent movie clip should then be accessible by actions on the main timeline. Suppose that the movieclip name is MC so then the parent would be called MCh. I do this by making a new movie clip and then changing the name to "MCh".
But when I try to use the dot syntax from the main time-line it doesn't seem to know the object. So I can't do something like "trace(MCh.width);". I can get what I want by creating the handled movie clip and then the parent and then putting the handledMovieClip into the parent with addChild. It works if I do it from the main time line, but not if I try to do the exact same thing within the class constructor. I thought it would be a nice feature if the user only had to make the handledMovieClip and if the parent was generated by the class constructor automatically.
How to make a movieclip accesible from any class and especially, hitTest-able? I.E. I can check collision it's with any class I want.
View 14 RepliesAssume I know practically nothing about AS3! I'm using Flash Pro CS5. I'm trying to reassociate a flash file I've been given with its external assets and classes. In the library I have a movieclip with linkage to a class called 'StaticMap' using the base class 'flash.display.MovieClip'. am I missing a custom class file called 'StaticMap.as' that was originally located in the same folder as the fla, or is this a generic class accessible to all movieClips from within Flash?
View 7 RepliesOk, 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?
I'm trying to access a text field from what I believe is called a sub-class. The text field is defined in the .fla file and the .fla file is set up to use Main.as as its document class.I got three files; scrollText.fla, Main.as and TextUtils.as.I know most of the code is working as I programmed it all in Main.as first, but when I moved the code to target the text field into its own class file I ran into error "1120: Access of undefined property" although I have declared the variable correctly and early enough to be used at this point in my code.This is the code I got so far:Main.as
Actionscript Code:
package{ import flash.display.Sprite; import TextUtils; public class Main extends Sprite public function Main()
[code].....
This is for AIR: My document class imports a separate class "ConnMonitor" and uses it to constantly monitor the network connection. It's at the very end of that class where it's supposed to update a textfield on the stage as the connection changes, but the class can't access the textfield.
View 8 Replieshow to display a variable from within a class in a textfield on the stage? I've been trying for ages and can't figure it out...
View 4 Repliesim struggling a bit with syntax here -- i'm trying to add a method to my multiplayer flash games then when an arrow hits an enemy, it will display the dmg, while scrolling up and dropping off alpha.I seem to be having some linkage problems this is what i have:
var dmgwin:dmgtxt = new dmgtxt() //movieclip that will contain textfield
var dmgwinsub:TextField = new TextField(); //textfield that has dmg #
var tween:Tween = new Tween(dmgwinsub, "alpha", None.easeOut, 1, 0, 2, true); //an alpha
[code].....
Is there a way I can reference a Movie clip I have on the main stage from a custom class of a document class?[code]
View 1 RepliesI am creating a custom Flash component with AS3. My component's main class imports a class with a static variable. How can I make this class accessible by the user of my component from a flash-level? This is the example:
my component's main class:
package
{
import flash.display.MovieClip;
import MyStaticClass;
[Code]....
The thing is I don't want to provide the user with the MyStaticClass source. I would like it to be automatically imported and accessible after dragging the component to the stage.
I have made a very simple swf in which I have a MovieClip which I have rotated on the stage. When I try to access this rotationX and rotationY properties of this clip using the constructor of the class assigned to this MovieClip they are coming back as 0 even though they shouldn't be. If I put an on rollover event of the MovieClip and trace out these properties here I get the correct values.
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
[Code].....
I also get the correct values when I read the values from the stage timeline.
trace ("TEST "+testMC.rotationX+" "+testMC.rotationY); //returns correct value
Is there a specific event I need to be waiting for which will tell me when the 3d properties are available via ActionScript?
This one is a funny one. To replicate:
1.Drag a radio button onto the stage.
2.Name the instance.
3.Create a document class.
4.Try and set/change the label of the radio button from the document class.
I noticed this problem when I quickly knocked the code together to catch the radio button value through an event, which worked perfectly when the code was on the timeline. I tried to clean up the code into a class file, at which point it broke. I stripped the whole thing down to bare bones and just could not get the label or the value to set from the document class. If I've missed something, I'd love to hear it, as I've wasted hours AGAIN on a silly problem.
[Code]....
Is there a way to refer to a Movieclip on the stage from a class file of the document class
Lets say I have 3 MovieClips on the stage(a Circle, a Square and a Triangle)
I have the document class which calls another class that controls the MC on the stage
Example
ActionScript Code:
package {
public class Example extends Sprite {
//Create the instance of the class being called
[Code]....
I'm just creating a movieclip from a text field object on the stage, giving it an instance name and setting some timeline animated over and out states for it. I'm then setting it up in AS3 to work like a button, so nothing complicated at all. But I am getting errors I have never seen before. Code is very simple basically I have a button called 'hair' contained within the mc 'menu', here it is:
Code:
menu.hair.addEventListener(MouseEvent.MOUSE_OVER , itemOver);
function itemOver(e:Event):void {
trace(e.target);
e.target.gotoAndPlay('over');
}
So I noticed there are some new text options in CS5, but none of them give the result I want. If I leave this as the (now default) TLF text, it gives a couple of errors related to this no longer being a movieclip;
Code:
ReferenceError: Error #1069: Property gotoAndPlay not found on flash.text.engine.TextLine and there is no default value.
at CL022_fla::MainTimeline/itemOver()
[object SimpleButton]
ReferenceError: Error #1069: Property gotoAndPlay not found on flash.display.SimpleButton and there is no default value.
at CL022_fla::MainTimeline/itemOver()
[object TextLine]
If I change it to classic, there are no errors, but the gotoAndPlay does not work. If I change the text to outlines, it works as per normal.
i want to access a movieclip or a textfield placed on stage within a static function defined in a class not in a document class ..
View 1 RepliesI created a custom class (no arguments needed for constructor) and I wanted to create an instance of that class that can be accessed by AS from aywhere inside the SWF (i.e. globally from any function or class).So far the only way I can think of doing that is to create the custom class with an associated MovieClip Symbol, drag an instance of that MovieClip Symbol to the stage, and then give it an instance name. It seems like I can then use the instance name to access that class instance anywhere.
View 4 RepliesIs there a way to add text programmatically in as3 to a Sprite or a MovieClip without using the class TextField
TextField inherits from InteractiveObject which is kind of heavy for what I want to do: just display text (i.e. I don't want to interact with the text).
Note: I'm aware that there is a property selectable to make the textfield not selectable. This is not the point.
ive been trying to get a mouseover working but im having some trouble.
I need it so when i mouseover a movieclip text appears in a textfield at the bottom of the stage.
also when i click the mc the text stays there as im dragging it into the correct location.
I would like to declare in my class a set of events that get dispatched by it and then use this information from controller class to automate addition of the event listeners. Is there a language structure for this in Action Script 3?
View 1 RepliesWhen you initialize a new object, how can that class have access to a variable from the parent?In this case Blob needs to be able to access scale?[code]
View 2 RepliesIn Flash Professional, I have a MovieClip and that clip has children. Let's say the parent clip is a night sky and the children are different instances of a star MovieClip that animates in a loop. This whole thing compiles down to a NightSky.swc which I use in Flash Builder as part of a larger project.
In Flash Pro, I position the child clips with a high level of precision. From there, I want to assign properties to these "stars." Say, I want to assign "galaxyId" and "isRedGiant" but (and this is key) I want to edit those properties in Flash Professional and have those value accessible in Flex.[code]...
i placed a movieclip inside a movieclip A_Mc ( representing ClassA) . Now if i place another movieclip ( without naming, and making sure that automatic instance naming is Off via the flash IDE ), everything runs fine. But when i provide an instance name say b_Mc , then it MUST be able to be publically accessible. What is the logic behind this setup. Why while designing i cannot make a sub-movieclip which is private and inaccessible to others?
View 3 RepliesDoes anyone know if it's possible to link a MovieClip on the stage to a class? I have a MovieClip on the stage called: square_mc and I have this Move class (see attached code). Of course when I set the class linkage of square_mc to the Move class, square_mc moves down the screen, Move is working. But how would I attach the Move class to square_mc at runtime, when it's on the stage?
View 5 Repliespublic class MyClass extends MovieClip {
public function MyClass():void {
my_mc.addEventListener(MouseEvent.CLICK, action);
}
private function action(e:MouseEvent):void {
[Code]...
I can't able to access the my_mc(placed in FLA) movieclip. How do I access?
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?
I'm getting really tired of AS3 now because I cant get it to do basic things like hit tests which were so easy in AS2. Basically, I generate a number of fish of varying scale, speeds and directions using this on the first frame of the timeline and the constructor function in the fish.as file:
ActionScript Code:
function DisplayFish() {
for (var i:int = 0; i < 20; i++) {
var newFish:fish = new fish();
this.addChild(newFish);
[Code] .....
What I want to do is rather than setting a max / min x/y use a hit test with a side wall MC on the stage, and a hit test between this instance of fish and all other fishes so they bounce off each other. I've tried so many ways of hit testing from within the class with MCs on stage but just cant get it to work.
ActionScript Code:
if(this.hitTestObject(root.LeftWall)){
directionX = 1;
}
Does anyone know if it's possible to link a MovieClip on the stage to a class?
I have a MovieClip on the stage called: square_mc
and I have this Move class (see attached code).
Of course when I set the class linkage of square_mc to the Move class, square_mc moves down the screen, Move is working. But how would I attach the Move class to square_mc at runtime, when it's on the stage?
package {
import flash.display.MovieClip;
import flash.events.Event;
//
[Code]....
If you put a moviecilp on the stage and then write a class that extends movieclip, is it possible to make it so that this references inside your class refer to the movieclip on stage.
E.g. this.x would refer to the x reference of the movieclip on stage.
1.I have a MovieClip in the Library. There is a named and dynamic text box in the MovieClip. In Frame 1 of the .fla, I construct the MovieClip from the class StatusBoard and add it to the stage. There is one setStatus method in the class to set the text. This works fine.[code]
2.I have a bunch of buttons that I created from a class called LinkButton.as (they are MovieClips, not _btn buttons). FWIW, they are attached to other MovieClips, but they work fine. The trace output is fine. What I am trying to do is have the rollover change the text in the billboard.[code]
3. In lay terms, I used addChild to add a MovieClip with a dynamic TextField to the stagw and I want MovieClip buttons created from an .as class to be able to change the text on a rollover.What I can't seem to do is actually reference the billboard that I added using addChild from the .fla.The buttons work and trace the desired text, I can't seem to send that text to the billboard.