ActionScript 3.0 :: Calling A Function Inside Another Class?
Sep 9, 2009
I have the following two classes and can't seem to figure to figure out how to call a function in the top one from the bottom one. The top one get instantiated on the root timeline. The bottom one gets instantiated from the top one. How do I call functions between the classes. Also, what if I had another call instantiated in top one and wanted to call a function in the bottom class from the second class?
package{ public class Character{ protected var _hp:uint = 50; //Character Health Points protected var _power:uint = 5; //Damage dealt
[Code].....
I`m instancing a Character and a Player in the Main Timeline, all in frame 1. When I use: ""player.attack(character)"" it works fine by itself.
So I added the if (defender._hp <= 0) this.win() which gives me the following error:
1061: Call to a possibly undefined method win through a reference with static type Character.
"defender" is a Character instance, "this" is a Player instance and "win()" is a Player method. I try to call the Player method inside a Character method using the Player instance adding the "." and his method name
Do I really need to define the win() function in the Character class? Is there a bypass to use a subclass method in a parent class method if it`s called from an instance of the subclass?
I have an AS3 function that loads and audio file and then plays it. I have the pre-loader for the first audio file working - now I need to run the pre-load function before the 2nd audio file starts.
I am using tweenlite throughout my file. I am importing it on the root timeline and would like use it inside a movie clip without having to reimport it. How do I reference it from inside the movie clip? I thought I could do something like this, but it does not seem to work: parent.TweenLite.to(leaf1, 1, {alpha:0, delay:1});
theres a function on the main timeline, I want to call it from inside of a movieclip.the first error was that it couldn't find the function and then I found a post where a guy said I should try something like MovieClip(root).fn() which made sense but then I got the "cannot convert stage to movieclip" error.
I'm not sure that I'm on the right track here. I've got what is essentially a 'gateway' movieclip and depending on the CLICK a corresponding movieclip (form) is loaded -- these all being in their own AS file. There are multiple corresponding pages that will all load/close in their own fashion but the 'gateway' will reload in it's own function-- consequently, I have this function on the main_AS. Can I trigger this function from the sub class or do I need to move the 'reload' function to a 'reload' class.
I've been searching around trying to work this out for a while now. There's been various ideas popping up, like dispatchEvent etc but nothing that seems to be a clear, simple way of doing this.What I'm trying to do is call a function from a class seperate (but in the same folder as) my document class.Specifically, I want to 'spawn' an object and run a function within that object's class from my Main.as.The snippet I have at the moment is as follows;
In Main.as: var object:class_Object = new class_Object(); object.spawn();
I keep getting an "undefined property" error when I try to call an external function from within the Doc class. I added the error message to the Doc Class below so you can see where it occurs.
If I take the code from the Tooltip.as below and place it on the FLA's main timeline I can get things working fine, but I would like to move all script to classes. The document class structure looks like this:
Drag_and_Drop.as
Code: package { import Tooltip;// Import custom class public class Drag_and_Drop extends MovieClip {
[Code]....
I realize that I could just combine all the code in the Doc class to get it working, but it would be nice to separate out this particular code which has only one use.
I'm trying to have a class reference a variable within the document class and have scoured the web but can't seem to find a solution. It seems relatively simple, but is a major stumbling block for me.
I want the variable in the doc class to increment each time a draggable object is within bounds and snapped to a box in the subclass. By tracking successful snaps, the objects will be placed one under the other each time.
I have a function I made in the root timeline. Inside of a movie clip, I have a button which calls the function in the actions layer in the root timelime.. how do I make this work?
I'm using loadMovie to load in an external SWF file. I'm looking to call a function called setText() inside of this swf. I can get to the function by doing this:
I have a SWF that is used to load other swf to it.
each of the loaded swf files has its own button events that try to access javascript functions. The problem is that they can't access the javascript. It never gets to call the functions.
If i run those swf on their own then it works..
what should i do do have embedded swfs to call javascript methods ?
Okay so I am reading through sens tutorial on OOP and updating my game that I am making. It is much easier to code this way (IMO) but still hitting snags.I am trying to get through this code:
I need to call a function inside a Flash Movie via JS (to update a textfield and sum Vars) can someone point me in the right direction???I tried to figure out the external interface api, but i dont understand how it really works ... For example: JS calls function "Fieldupdate" and in the Flash Movie the Fields and Vars Updates
Okay so I am reading through sens tutorial on OOP and updating my game that I am making. It is much easier to code this way (IMO) but still hitting snags. I am trying to get through this code:
I have a movie clip on the stage which contains 4 frames and i wanna call a function from for example frame number 4... Obviously i wanna call this function from the main timeline containing all the MC. How can i do that, i have been looking around but cannot find much...
I have a two classes. One is linked to a menu and controls that. The other is linked to a 'viewer' movieclip. At the start (in the contructor function of the classes that relates to that mc) the 'viewer' mc feeds off an XML document, and an image is loaded into itself. When I click on a menu tab I want the image to change.
Both the viewer mc and the menu mc are on stage already. I tried to import the viewer classes into the menu class...
I;m converting some of my as2 classes to as3 and have run into a problem where my ships class cannot seem to call my vectorGraphics class. They are in the same folder (sprites).
The basic flow is this: On the main timeline I instantiate Ships and vGX.
I've been searching around the forums to find a solution of this problem. I have two classes: Monster and Player. Constructors are defined and the classes by themselves apparently works. My problem is that I want to get player.x inside the Monster class.
I'm trying to call a function to another class after an event.
Here's my code:
From the doucment class:
public static function redrawMap():void { removeChild(global.world); var world:WorldHandler = new WorldHandler(40,30);
[Code]....
I can't get it to work correctly, I get weird messages like "Call to undefined method removeChild" and it pointing to the redrawMap function. Which means it found the function, but I can't seem to do anything with it.
I have two classes. One called Sledge and one called Sock, there is also the document class called Main. My issues are as follows: Inside of Sledge, I call a function that is defined inside of the Main document class. How would I go about telling the class to go to the document class and run that function? Would this also be the same for other classes or just for the document class? Inside Sledge, I have the following statement: if(hitTestObject(sock.myHitArea)) { /* somecode*/ }
sock is an instance of another seperate class, and by this point has already been created. However when I try and run this I am told it is not defined. How would i go about solving this?
I have done this type of thing a million times before, but I cannot for the life of me figure out why it isn't working this time. As of now I have three classes: Main, UI, and Bear.
Main creates an instance of UI and puts it on the stage. UI has, among other stuff, 7 instances of the Bear class sitting on the stage. The Bear class has a public function: