ActionScript 3.0 :: Linking Class With Stage Object
Feb 13, 2009Linking class with stage object..
View 14 RepliesLinking class with stage object..
View 14 RepliesI've just started using classes while developing my basic platform game in Flash AS3.
On the stage I have a character, instance name 'ball_mc'. I have AS in the time line which controls the characters movements.
I have an external AS file named 'Ground.as' which is basically an ENTERFRAME hittest which stops the character from moving when the character 'hits' the ground.
I have placed a rectangle MC on the stage to represent the ground and linked it to the external AS file 'Ground.as'
The Code for Ground.as is as follows:
package
{
import flash.display.MovieClip;
import flash.events.Event;
[Code]....
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?
View 5 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?
package {
import flash.display.MovieClip;
import flash.events.Event;
//
[Code]....
Ok. So heres what I am trying to do. I want one movie clip to follow another one that I move around with actions on the main timeline.The problem is that the follower clip is linked to a class file and I cannot find a way to find the players position.
[Code]...
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?
The following is that long only because I gave examples of what I want to know, not because it is complex .I have three basic questions regarding AS 3.0 classes.
1. How can I make a class object interact with an object on stage?
For example, when I have a square (mc_Square) with class "square" attached to it and I want it to trace "Colliding!" and print the X and Y of the mc_Box on contact with an on-stage *hollow* box (mc_Box) that has no class attached to it.how to do it vice-versa would also be awesome .
2. How can I make a class object interact with the same class object? For example, when I have two squares (mc_Square) that both have the class "square" attached to it and when they collide, it prints the X and Y of both of them.
3. How can I make a class object interact with a different class object?
For example, when I have two squares mc_Square1 with class "square1 (that also has a variable Primary=true written in it)" and a mc_Square2 with class "square2"; When they collide, the one with Primary=true would be removed and it's X,Y position traced.
I have a custom class which uses some buttons on the stage. Or at least is trying to.say have this code in the customClass.as file
package{
import flash.events.*;
import flash.display.MovieClip
[code].....
How you can assign a class to an object on stage.[code]...
This would make a new object, but the current object already exists, it just needs to be notified that it's of the type "ClassName" so it can inherit it's properties.I've also tried assigning the "ClassName" in the linkage as either the base path or the class name. But in either situations I get an error saying that the class needs to be unique when I use the same class on multiple objects.
I have a document class called Main, and a class called DispatchEventExample. In DispatchEventExample, I'm trying to add an event listener to the stage but get an 1120 error, access of undefined property stage.
If I understand things correctly, even though I create an instance of DispatchEventExample in Main, it's not added to the display list & therefore cannot access stage.
[Code]...
I have a class that have a method to do some work and return a MovieClip. How can I access the stage from the class ? I don't add the class object to stage.
My code is like this :
Code:
import com.ClassName
.
.
.
var c:ClassName= new ClassName();
var mc:MovieClip;
mc = ClassName.create("some parameter");
I want to get access to the stage from ClassName class file.
I've googled this to no avail, I've only found how to manipulate the stage itself and not a display object on it,I have a movie clip on the main timeline with instance name displayName. I created a button that should change what frame displayName goes to (in order to...did you guess it?! diplay the Name of the button.So I am trying to write the code in a reusable fashion and have the buttons all linked to a class called GeoPuzzle. Inside GeoPuzzle I instantiate a touch event and run the code. However, the function has to be able to change displayName in the main part of the timeline and, of course, the compiler says displayName doesn't exist because I'm in a class and I'm talking about the stage.[code]How can I tell displayName to change it's current frame from within display object class?
View 9 RepliesI'm currently trying to add the resulting XML (xmlResult) to a textbox that is on the stage. I did try using MovieClip(root).[instancename].text = ..... however it didn't work - null object reference?
package {
public class ChatHistory extends MovieClip {
public function ChatHistory()
[Code]....
I want to rearrange an item on stage when the visitor changes the browser size. The item is initiated in an external class G94Menu:
ActionScript Code:
public function addItem(item:MenuItem):void
{
item.y = (item.height + _spacing) * _items.length;
[code]....
I have a media player that I am codging together, one that will play either videos or MP3s depending on the variables it is passed. The video player part works fine. The MP3 player controls are all actual physical MCs on the stage; each one has its own AS class file as part of the package, but there is also a lot of AS that is happening in the main FLA as well. Messy, I know, but it mostly works great.
The MC on the stage in the main FLA is properly linked to the class file via Actionscript linkage, and the control itself works. However, I am trying to make some aspects of the control respond to variables that are set within the AS on the timeline of the main FLA, and I cannot seem to pass values to the control no matter what I do.
[Code]....
I was wondering if there is a simple way to access variables from a class object, where the variables are not actually a part of that class. So if you had an array defined on the first frame of the stage, and added some elements to it, you could use the methods of the custom class to manipulate the array's data.
Stage Frame 1
Code:
var myArray:Array = new Array( "apple", "banana", "pear" );
var myClass:someFunctions = new someFunctions();
myClass.addValue( "orange" );
myClass.sortValues();
[Code] .....
It might not seem logical as to why you would ever want to do that, but it's a very simple example, and it's the means I'm after, not the result. I'm creating a list of functions available to execute by a user via an input field. To keep things simple I made them the methods of a class. The issue, however, is that these methods need to manipulate objects which are on the stage, added and removed by a separate controller class. Passing the objects by reference to the class as a parameter would not be viable with what I'm trying to do either.
The use of library classes confuses me once again. I have the following situation:
[Code]....
I cannot put in any baseclass when using the class, so I'm forced to remove the baseclass. When using only the class I get a whole bunch of errors don't make any sense at all, and still appear even if I comment out all the code in the Page class. comop_padpagesFavorietenPage.as:7: 1152: A conflict exists with inherited definition com.op_pad.pages:Page.help in namespace public.
[Code]...
I have a dynamic textfield called neighName on my Flash stage. I also have a movieclip that I call a region on my stage. When I mouseover the region, I want a word to display in a little popup *and* I want some text to display in my textfield. I have an external .as file for handling the region. I can make the code "see" my region, but I can't seem to make it see my textfield, although no errors are being thrown.
View 1 RepliesIs there a way to make an static method act over an object of its class that is already on the stage, without using the keyword "this"? I mean, like "generic object of this class: do what I'm telling you to do, wathever your instance name".My goal is to create an method that get called by any object of this class, based on the changing on the value of an external variable, but since I cannot use the "this" keyword to reffer to each instance, I could not figure out a solution.
View 1 RepliesI have a media player that I am codging together, one that will play either videos or MP3s depending on the variables it is passed. The video player part works fine. The MP3 player controls are all actual physical MCs on the stage; each one has its own AS class file as part of the package, but there is also a lot of AS that is happening in the main FLA as well. Messy, I know, but it mostly works great.The MC on the stage in the main FLA is properly linked to the class file via Actionscript linkage, and the control itself worksHowever, I am trying to make some aspects of the control respond to variables that are set within the AS on the timeline of the main FLA, and I cannot seem to pass values to the control no matter what I do.The following variable is set in the main AS:Code:var notPlayedYet:Boolean = true;I also have some flashVars being passed in from the html, and these I can reference with no trouble from the main AS - the relevant one is:
I have this code in a class:
Code: Select allpackage com.jhoyt{
import flash.net.URLRequest;
import flash.events.*;[code]....
and I have this code on the timeline of the movie its being loaded into:
Code: Select allimport com.jhoyt.SSIlaunch;
var ssi:SSIlaunch = new SSIlaunch();
addChild(ssi);
I know its loading because I can put trace actions into the addAndPoint function and it gets called. what can I do to make it display?
I have this code in a class:
[Code]...
I know its loading because I can put trace actions into the addAndPoint function and it gets called. what can I do to make it display?
In the first function homeL adds the 'restMenu' text field when it's called. In another function the hideTarget method is called and it checks to see if the objects name is "instance5" which is the name of homeL. Is there a way to link an objects name to the object because I get :
[Code]...
I have a class called shapeC that only creates a rectangle and then addChild(rectangle);. That class is instantiated on the main timeline. Currently, the only way you can see that rectangle is to add the instantiated class to the stage via addChild(shapeC);. My question is, is there a way that the shapeC class can add the rectangle to the root stage without requireing the instantiated class to be added to the stage?
View 4 RepliesI would like to link a loaded SWF with a particular class at run-time. This is because I would like to have a main SWF with all the code that loads in other SWFs that purely act as graphical skins for the main class. Consequently I would only need to re-export the one file when code needs to be changed rather than have to do a myriad different colour variations (which is what happens currently).
I remember back with ActionScript 1 you could register a class (such as they were) with an exported library item using code rather than just using the library in the Flash IDE (as is the case now).
I've tried everything within my knowledge, searched the related posts but still can't find anything that works, this is what i have
[Code]...
I've tried replace stage with _parent, and _root and so on but I'm just stumped, been tryin to get this workin for over a week on and off already, still notta
I have a string array with a list of words,e.g. var textArray:Array = ["a1", "b2", "c3", "e5"]Then I also have an array with a list of buttons that are visible on my stage,e.g. var objectArray:Array = [a1_btn, b2_btn, c3_btn, d4_btn, e5_btn]m wanting to use actionscript to make the buttons that are writen in the text array to be visible onscreen, and the buttons that arn't written in the text array to be invisible.
View 4 RepliesI have a simple progress bar symbol (ProgBar) in the library of main.fla. If I don't define a class and allow Flash to assign a placeholder class of ProgBar, then the symbol displays ok using progBar = new ProgBar();addChild(progBar); If I define a class, even the basic empty version below, I get the following error: ReferenceError: Error #1056: Cannot create property percent_txt on ProgBar. at flash.display::Sprite/constructChildren() at flash.display::Sprite() at flash.display::MovieClip()
Class code:
package { import flash.display.*; import flash.text.*; public class ProgBar extends MovieClip { public function ProgBar(): void { } }}
percent_txt is a text field I've given an instance name to. If I delete the text field (or its instance name) the error changes to reference the next item in the symbol and so on until there are none left!
I am currently having a problem with Flash CS5. I am trying to link a sound file to my Flash game without having to put it on the stage. It would play when my character got hit by an enemy. The problem is is that when I go to edit the properties, all of the options except to play the sample are all blanked out. This is currently driving me insane as I have done everything I could think of to get around this.
View 1 RepliesI just want different-looking movieclips to move in the same way so that I will only have to edit one file if I want to change their behavior, instead of copying the class file and renaming each one, and then I would have to edit the builder function name and class name inside each one as well, even though it would do the same thing.
View 2 Replies