Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Calling A Function, External To The Calling Class



hello to everyone, who looks at this postSo there's a class, that needs to call/access an external function.'External' (imho) in this case would be any function, declared outside of the class.How is it possible to:1) call a function declared in the main timeline.2) call a function in another class (i suppose, the only way of doing it is by importing the class having this function into the calling class?)



Adobe > ActionScript 3
Posted on: 07/07/2008 12:33:46 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Calling A Function In Main Class From A Loaded Swfs Document Class
Hi
I have a main.swf that loads page.swf. They each have a document class called "Main" and "Page".

How can I call a function in Main from Page?

In AS2 this would be somthing like _parent.myFunction();


Cheers

Calling A Function In A Class
Hi guys,

I currently have this class:
A lot of it has been removed since they are not relevant:


Code:
class ProcessRss {


//declare public properties
public var targetClip:MovieClip;
public var textTarget:TextField;


//constructor
function ProcessRss (_mc:MovieClip, _ta:TextField, _proxy) {
targetClip = _mc;
textTarget = _ta;
proxyPath = _proxy;
_xml = new XML();
_xml.ignoreWhite = true;
_xml.onLoad = Delegate.create(this, processFeed);
}

public function timer():Void {
myInterval = setInterval(this, "ticker", delay);
}

public function stoptimer():Void{
clearInterval(myInterval);
}
}
On my timeline:


Code:
//bring in the parsing class
import ProcessRss;

//create instance of the parsing class
var pcnews:ProcessRss = new ProcessRss(holder.reader, holder.reader.reader, "rss.php");

Now, let's say i have a button on my stage called setScroll.

How do I make it call timer() (which is in the class) when it is pressed?

thanks!

Calling A Function Within A Class
Hi I have created a basic class that says hello when the runs but I want to know how to call the sayGoodBye() function with a mouse click on a button or movieclip.

Thanks,







package {
import flash.display.*;
import flash.events.*;
import fl.transitions.*;
import flash.display.MovieClip;


public class Greetings extends MovieClip

{



public function Greetings()
{
trace('hello');


}




public function sayGoodBye()
{
trace('see ya');
}

Calling A Function On The Timeline From A Class
Here is my problem, i have a class and function on the timeline, which I want to call from within the class on certain event but the function is not being executed. what am I doing wrong- this is what I have on my timeline:

Code

var myXML:xmlLoader=new xmlLoader("managment.xml");
myXML.dothisFunction=function(){
trace("hello");
}


this is my xmlLoader class definition:

Code:


class xmlLoader {
public var xmlFeed:XML;
private var doFunction:Function;
public function xmlLoader(xmlUrl:String) {
xmlFeed = new XML();
xmlFeed.ignoreWhite = true;
xmlFeed.onLoad =init;
xmlFeed.load(xmlUrl);
}
public function set dothisFunction(callBack:Function):Void{
doFunction=callBack;
};
private function init(success:Boolean) {
if (success) {
doFunction;
} else {
trace("oops");
}
}
}

As3, Calling A Function On Stage From A Class?
Hi guys could one of you tell me how I can call a function on the stage from within a class? I am getting "Error #1007: Instantiation attempted on a non-constructor" by trying to do it. This is a dirty as2 to as3 conversion so the path of least resistance would be best. If anyone could help it would be great

Calling A Function Within A Class From Root
On my main timeline, I have a movie Clip called mp3Player that has a class mp3player.

The mp3player class has all of the functions controlling the buttons, playback, etc.

The site also contains a flv player. If someone clicks to load the flv player, I need to stop playback of the mp3 player.

Is it possible to call functions within the class from the main timeline? Or to trigger a mouse event on the stop button?

I've tried calling the instance but I can't figure out how to access anything within that movie clip.

I've tried root.mp3Player.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
... but I get a Error 1010: A Term Is Undefined or Has No Properties.

Anyone know how to accomplish this?

Thanks!

Calling A Function In Parent Class?
Simple question:

I have class that controls a container MC (Tree). Inside this class I add new profiles.

var profile:Profile = new Profile();

The profile can be dragged around and repositioned in the container grid. When the profile is released I want to notify the parent where is was dropped.

If make this call from the profile class: parent.positionNode(lev,pos);

I get an error: 1061: Call to a possibly undefined method positionNode through a reference with static type flash.displayisplayObjectContainer.

If it possible to call a parent like this or is there some other way?

Calling A Timeline Function From A Class
I am finally migrating to AS3 and having some issues doing some of the fundamental things I used to do with AS2. I figure what I want to do here should be simple enough, but I've been searching everywhere for an answer and have not found one.

I've created a class for buttons so they all have the same properties and rollovers. I have a global function on my main timeline that will set up all the animations I want to transition to a new page in my website, once the button is clicked.

I just want to call this function once the CLICK event is dispatched from within my as file.

Something like this (pulled from my ButtonClass.as file):


ActionScript Code:
this.addEventListener(MouseEvent.CLICK,goPage); // from constructor function

public function goPage(event:MouseEvent):void {
root.goTransition() // this function resides on my main timeline
}

Any help is greatly appreciated.

Calling Constructor Function Within Same Class
Dear users,
I have a document class name elevator and my constructor is also elevator as usual
How to call this constructor function within elevator class? Is is possible or not?
Please guide me on this.

Calling A Function From Method In Class
Is this possible, I create an instance of an object - This is on my main.fla


ActionScript Code:
var newClass:MovieClip = new myClass;

newClass.myFunction();

function myMainFunction () {
           trace("works");
          }

now lets say this is the class file called myClass.as


ActionScript Code:
public class myClass extends MovieClip {

        public function myFunction () {
                         myMainFunction(); //this is where I want it to run on the function on main timeline

                  }
}

any ideas? I've tried putting parent. before it etc - just to note this isnt my actual code I'm working on but a simplified version of it.

cheers

Problem Calling Function Of A Class
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:


Code:
public function setType(type:Number):Void
{
trace("here");
_type = type;

switch(_type)
{
case Main.NORMAL:
bear.gotoAndStop(NORMAL);
break;
case Main.BLOCKER:
bear.gotoAndStop(BLOCKER_IDLE)
break;
case Main.BOMBER:
bear.gotoAndStop(BOMBER_WALK);
break;
case Main.BOXER:
bear.gotoAndStop(BOXER_IDLE);
break;
case Main.FOIL:
bear.gotoAndStop(FOIL_WALK);
break;
case Main.GENIUS:
bear.gotoAndStop(GENIUS_WALK);
break;
case Main.JACKHAMMER:
bear.gotoAndStop(JACKHAMMER_IDLE);
break;
case Main.PARACHUTE:
bear.gotoAndStop(PARACHUTE_WALK);
break;
}
}
in an init() function of UI, I call setType on all 7 of the Bear instances so that the MovieClips associated with it will go to a frame and stop there. I get NO errors when I compile, but the setType function is never being called. I know that the class itself is being instantiated though because I can trace out from the constructor of Bear and that traces fine.

HELP... if you can please! haha

Thanks,
Kyle

Calling Class-function Issue
I have a really strange problem accessing a memberfunction of a class I made.

Essentially, when I create a class-instance just using regular code:

ActionScript Code:
var myClassInstance:myClass = new myClass ();

..I can access memberfunctions without any problem.

But (and here is where it goes crazy), when I write a function that will create this class-instance, and calls it to create an instance, it is impossible for me to access the member-functions.

ActionScript Code:
CreateInstance();
 
function CreateInstance(){
    var myClassInstance:myClass = new myClass ();
}


I mean, it just seems insane that there would be any diffrerence wether I create an instance using a function or not.


Here is the fla-file. In the .as-file there are the two alternatives for creating the instance at load. The button then tries to use the member-function of the class to move the class-instance (which is a movieclip) horisontally.

http://www.kirupaforum.com/forums/at...achmentid=2465

Calling A Static Class Function From The Timeline
Hi there!

I have a (small?) problem when calling a static function in a class from the timeline:

In AS2 I used to do it like this (this code is in frame 1 of the _root timeline):


ActionScript Code:
import com.mypackage.Application;

// call to a static function main() in Application
com.mypackage.Application.main();

how do I do this in AS3, I always get this compiler error:
1202: Access of undefined property Application in package com.mypackage.

thanks for your help!!

Calling A Function In The Root File From Another Class
I've got a root file with let's say the public function MyFunction():void... then in a different file, let's say secondClass.as class, I need to call that function. I have tried everything I can think of to call it and I can't seem to do it. This seems like such a dumb question! Thanks for the help.

Calling Actionslistener Function On The Stage From A Class
I have a sound class that calls an actionlistener when the sound has finished playing (Event.SOUND_COMPLETE), but I can't seem to figure out how to make the sound complete event call a function on the stage.

I've searched around and the usual solution is to addChild() with the class first or else the stage is null, but I can't use addChild() in sound classes. What I've been doing instead is calling a function in the class adding the property isDone=true, then looping on the stage every frame until it sees it's true. There's gotta be a more efficient way. Please help



channel=this.play(...);
channel.addEventListener(Event.SOUND_COMPLETE, stage.someStageFunction)

Calling A Function With A Argument In The ContextMenuItem Class, How?
hi,
im tryng to call a function with a argument in the ContextMenuItem class.

code:


ActionScript Code:
function down(id){    txt.text = id;    //trace(id);};var my_cm = new ContextMenu();menuItem_cmi = Array();for (i=1;i<6;i++){    menuItem_cmi[i] = new ContextMenuItem("product: "+i, down(i));    my_cm.customItems.push(menuItem_cmi[i]);}my_cm.hideBuiltInItems();cart.menu = my_cm;


It seems that when ever I try to send an argument with the down function, it simpley dont work and without it, it does work

Calling Parent Class Function Problem
Hello, I have 2 Classes
main.as
and
gallery.as

in main.as i'm creating new object for example:
gl:Object = new gal(); // gallery.as class

in gallery class i have fadeOut function that fades out img, i want to make something like event onFadeOut to call from main as .

i want to know when img fadeout is done in main.as.

sorry for my english

Class's Movieclip Calling A Function In It's Own Class
For the life of me I can't find an internet source that explains why this doesn't work. I know it's a scope problem but I know no other way around it and there must be a way to do it, I'm thinking.

I have a class. Inside this class I create a movieclip which I have a class variable link to. The movieclip is created on _root. When I click on this movieclip, I want it to call a function inside the class. Here's what it looks like.


Code:
class Whatever extends Movieclip {
private var mc:MovieClip;

public function Whatever() {
this.mc = _root.createEmptyMovieClip("rootmc",_root.getNextHighestDepth());
[code for drawing a square]
this.mc.onPress = this.doSomething();
}

public function doSomething {
[do something]
}
In the above sample, when I click on the movieclip, the "doSomething" function is not called, obviously because the movieclip is on root and has nothing to do with the class. Is there a way to do what I want to do?

[FMX04] Calling Function On Movieclip From Class Method
Is it possible to call a function defined in a movie clip from a class?

Here's a sample project setup I'm trying to achieve this simple feat:

func.fla
- Has one movieclip "fooinst" which is library item "foo".
- The "foo" library item has linkage is to the "Foo" class
- The "foo" library item has one script on it's first frame:
ActionScript Code:
function bar() { trace("bar() called"); }
- The "Foo" class only has this:
ActionScript Code:
class Foo extends MovieClip{    public function Foo()     {         trace("Foo() constructed.");        var mc : MovieClip = this;        mc.bar();    }}

When run, bar() is never called. (I believe it's undefined.)
How do I call bar() from inside the class?

ActionScript Class Problem Calling A Function From A Method
I'm relatively new to the wonderful world of ActionScript 2.0 OOP. I'm hoping this problem is an easy one to solve, though I cannot seem to find the answer anywhere.

It would seem that you cannot call a method from a function contained within another method. For instance, the following would be contained in a class that displays and manipulates images:


Code:

private function fadeIn (target:MovieClip):Void {
var a:Number = 0;
var incr:Number = Math.round(100/fadeDur); // fadeDur is a static var set earlier in the class

container_mc.onEnterFrame = function() { // container_mc is the movie clip containing the image that we're fading
// fade the movie clip in
this._alpha = a;
a += incr;
if(a>=100) {
pauseMC(); // this is the offending critter
delete this.onEnterFrame; // stop the fade
}
}
}

public function pauseMC ():Void {
trace("waiting...");
var dur:Number = getDuration(); // a function that returns num of milliseconds
var b:Number = 0;

function endWait(myIntervalId) {
trace("ending wait. Attempting to unpause");
unpauseMC(myIntervalId); // another instance of a method that doesn't get called
}

// unpause the mc after the random duration period
var myIntervalID = setInterval(endWait, dur);
}


So in the example above, the two method calls, pauseMC and unpauseMC, never fire off. Any non-method calls such as 'delete this.onEnterFrame' fire off just fine. And if I move the method calls out of the sub-functions, they work just fine. It's only when the method call is contained within the subfunction that it does not work. For the life of me, I can't figure out why.

Can anyone provide some insight?

Many thanks,
Steve

OOP In Flash: Calling A Function W/in A Function Class?
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:

ActionScript Code:
House = function(){        this.floors = 4;         this.siding = "Red";         this.outputSiding = function(){            trace(this.siding);         };     };         // create an instance of the House class     myHouse = new House();     myHouse.outputSiding(); // traces "Red"  

Now as it seems to me, I have nearly the same thing (I will condense this to save space):

ActionScript Code:
//set new character function()character = function (depth, x, y, charType, name, HP, MP) {    //sets stats used; this works fine :)        //attachMovie and set x/y     _root.attachMovie(this.name+"_mc", this.name+"MC", this.depth, {_x:this.x,_y:this.y});    /*this is where I am having trouble; it won't do anything!I have tried tracing to no availalso, can I set the x and y coords somehow with thealready made object x and y? I am tired right now andcan't think of a way but what I have done, which doesnothing as this function won't go!*/    statsBox = function(depth)  {        this.depth = depth;        trace(this.depth+newline+'hello');        this.x = enemy._x+130;        this.y = enemy._y-50;        _root.attachMovie("stats_mc", statsNameMC, this.depth, {_x:this.x,_y:this.y});    };};enemy = new character(30, 350, 200, 'enemy', 'genericName', _root.EHP, _root.EMP);enemy.statsBox(50);

that's it, pretty much. So what's wrong? Maybe I'm too tired for this right now...
thanks.

OOP In Flash: Calling A Function W/in A Function Class?
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:

ActionScript Code:
House = function(){        this.floors = 4;         this.siding = "Red";         this.outputSiding = function(){            trace(this.siding);         };     };         // create an instance of the House class     myHouse = new House();     myHouse.outputSiding(); // traces "Red"  

Now as it seems to me, I have nearly the same thing (I will condense this to save space):

ActionScript Code:
//set new character function()character = function (depth, x, y, charType, name, HP, MP) {    //sets stats used; this works fine :)        //attachMovie and set x/y     _root.attachMovie(this.name+"_mc", this.name+"MC", this.depth, {_x:this.x,_y:this.y});    /*this is where I am having trouble; it won't do anything!I have tried tracing to no availalso, can I set the x and y coords somehow with thealready made object x and y? I am tired right now andcan't think of a way but what I have done, which doesnothing as this function won't go!*/    statsBox = function(depth)  {        this.depth = depth;        trace(this.depth+newline+'hello');        this.x = enemy._x+130;        this.y = enemy._y-50;        _root.attachMovie("stats_mc", statsNameMC, this.depth, {_x:this.x,_y:this.y});    };};enemy = new character(30, 350, 200, 'enemy', 'genericName', _root.EHP, _root.EMP);enemy.statsBox(50);

that's it, pretty much. So what's wrong? Maybe I'm too tired for this right now...
thanks.

Calling External Function
I have a project in Flash MX where I need to make some calculation too complex for Flash. So I need to use some other language than ActionScript. Can I link any C/C++ dll, or something like java?

Help Calling Nested Movieclips From External Class In AS3
Here's what I did:

1) I created a movieclip (book_mc) on the stage. Inside the book is another movieclip (bookPages_mc). Inside of bookPages_mc is a third movieclip (subNav_mc).

2) On the root layer I created another movieclip (button).

3) On "button" I went to Linkage and gave it a base class of my own creation, "MainNav".

Now in the MainNav class I want to tell the subnavigation movieclip to animate.

The problem is - I can't figure out how to reference nested movie clips from an external class.

(For the record - everything has an instance name and has been double checked. The code works from within the FLA but not from an external class.)

Here is my class code (everything works except for the reference to the nested movieclip):


Code:
package {
//imports
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.events.MouseEvent;
import flash.display.SimpleButton;
import gs.TweenLite;//Importing TweenLite (make sure "gs" folder is in same folder as this file
import fl.motion.easing.*;

//declare class
public class MainNav extends MovieClip {

public function MainNav() {
trace("activate Main Navigation button");
this.buttonMode = true;
this.addEventListener(MouseEvent.CLICK, handleClick);
}//end constructor function

function handleClick(event:MouseEvent):void {
//trace("handleClick");
book_mc.bookPages_mc.subNav_mc.gotoAndPlay("slide");
}//end handleClick method

}//end class
//end package
}

Please help! And please consider, when replying, that I pretty much only learned how to use classes YESTERDAY so I'm still a noob at this. Thanks in advance!

Calling Or Creating Objects From External Class
OK I'm sure there is a simple thing missing but i cant seem to figure out. heres my code:

var mc:MovieClip = new MovieClip();
mc.graphics.beginFill(0xFF0000);
mc.graphics.drawRect(0, 0, 100, 80);
mc.graphics.endFill();
mc.x = 80;
mc.y = 60;
addChild(mc);

this code works and shows the rectangle on the stage when its in the main class but when i put it in another class file and call the function from the main one it doesn't show anyone know why and how to fix it?

Calling A Function In An External Movieclip ?
Hello

I've been searching for some time now how to solve a problem, and I don't understand at all what I've done wrong, so here we go...

I've got a flash movie (simple_flash.swf). In this movie (only one frame), there's this :
code:
function simple_function(var1, var2) {
//do some great things
}


I load this movie from another movie (the main one) like this :
code:
//id contains something like "external_movie"
//z contains the z-index value for the new movieclip
_root.createEmptyMovieClip(id, z);
var my_object = eval("_root."+id);


I load my external movie clip using a movieClipLoader :
code:
//url is the path to simple_flash.swf
//my_object is the same as above
my_movie_loader.loadClip(url, object);


My movie shows up as expected, but I can't manage to call the function simple_function. I've tried this :
_root.external_movie.simple_function(x,y);
or
_levelxx.simple_function(x,y);
(I know xx), but nothing...

If I call trace(_root.external_movie), my movieclip is here, but trace(_root.external_movie.simpl_function) is undefined...

What's wrong ?

Thank you

Calling Function From External As File
Alright, I seem to be having trouble figuring out how to call a function from an external AS file from within a movieclip.
Anyone have any ideas?

Calling Function From External Movie.
Last edited by DavidNetk : 2003-09-22 at 19:08.
























Never mind it has been done.

Calling A Function From An External Text File
Hi,
Is it posible to call a function from an external text file?

Like this,
I load in my text file into a text field.
My field has HTML formating enabled and such.
When the user clicks on 'click here' it calls a function.

I know how to do it when the text isn't loaded from an external text file (asfunction:myFunction)...

But I have no idea how to apply that to an externally loaded text file.

Any help would be appreciated!

Calling A Function In _root From An External Swf's Button?
Is it possible to call and execute a function from a button (or mc) contained within a loaded external swf? I have tried with no success.

I'll try to explain this the best i can.

Basically, what i want to do is have a button that's contained in the "contact us" section that will open up a guestbook for visitor to leave comments etc. But on(release) of the button, i want to start the closing page transition for the contact page, which will unload the swf when it ends, and then load the guestbook into my container clip.

So in order for it to work properly and preload, i would assume that i have to call the function that my main menu buttons use to check if the page is already loaded, and if not, loadMovie() and start preloader.

Is this possible or not?

OH..... and one other question if anyone has an idea.... Each of the site section use a lot of the same function()s, so i was wondering if i created an external AS file that contained all of the functions that I used in more than one swf, can i save myself the time of writing the code into each and call the function()s contained within the external file?

THANKS IN ADVANCE!!!!

Flash 6 - Calling A Function On An External Swf Timeline
I've tried looking everywhere for this answer, but I'm still at a loss. I'm beginning to think it's not possible or I'm just not looking in the right places.

I have three swf files. The main container and then two external swf files being loaded into the main swf. Swf 1 (frame.swf) has a function on the main timeline that needs to be called from a button in swf 2 (toolbox.swf). My initial thought was to place the actionscript of frame.swf into a movieclip and call it from toolbox.swf using:

_root.callFunction("PH", "doPhone");

Although this would work, I cannot use this option. The actionscript of swf 1 must stay in the main timeline. Using a class file is not an option either. Is there any other way to call a function from the main timeline of an external swf?

Calling SetTimeout Within Custom Class And Cannot Access The Class' Variables
Hi All,

I'm creating an user interface with Flash 8, I'm new to Flash, my background is Java therefore I decided to use ActionScript to create a custom component that is reference within an external file.

My problem I believe is scope related. I have a status bar (label component), once I update the status bar I want to call the
"setTimeout" function to wait a couple of seconds before clearing my status bar. The "setTimeout" function is executing, but for some reason my status bar is not being cleared (accessed).

Below is a snippet of my code. Any help appreciated. Thanks.


/*
External File
*/
import mx.controls.Button;
import mx.controls.Label;

class MyApp
{
//private properties
private var mc_container:MovieClip;
private var btn:Button;
private var lbl_status:Label;
private var str:String = "do see me";

//constructor
public function MyApp(target:MovieClip)
{
trace("-- MyApp --");
mc_container = target.createEmptyMovieClip("mc_container", 100);
}
//public methods
public function init(width:Number, height: Number, xPos:Number, yPos:Number):Void
{
var my_app:MyApp = this;

btn = mc_container.createClassObject(Button, "btn", 1, {label:"click me"});
btn.setSize(100, 25);
btn.move(10, 10);
btn.clickHandler = function():Void
{
trace("btn clicked");
setTimeout(my_app.clearStatus, 2400);
//correct if I call directly
//my_app.clearStatus();
trace(str);
}

lbl_status = mc_container.createClassObject(Label, "lbl_status", 2, {text:"status bar message"});
lbl_status.setSize(200, 25);
lbl_status.move(0, 50);
}
public function clearStatus():Void
{
trace("calling clearStatus");
lbl_status.text = "";
}
}


/*
Called for Flash IDE
*/
var app:MyApp = new MyApp(this);
app.init(200, 200, 0, 0);

[Flash8] Calling BitmapData Class From Within Custom Class
I've written a custom class which resides in a .as file. Is there any way that functions from within my class can call the BitmapData class for bitmap manipulation?

Button Class Calling Class Method
I have this class to add code to some buttons on the stage, and the class also contains the code for the button actions.

How can I get the button code to call the search() method when the button is pressed?


Code:
class startup.Shell
{

function Shell ()
{

init ();
}
private function init () : Void
{
//buttons
_root.btn_search.onPress = function ()
{
search ();
}
//
public function search () : Void
{
trace("loadsearch");
}
}

Calling A Class
Hello,

I am playing around with papervision3D. I have set a class in an external AS file and put that file in the same document as my main FLA file.

my AS file looks like this:

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

    //import fl.transitions.*;
    //import fl.transitions.easing.*;
   
    import org.papervision3d.cameras.*;
    import org.papervision3d.core.*;
    import org.papervision3d.core.geom.*;
    import org.papervision3d.materials.*;
    import org.papervision3d.objects.*;
    import org.papervision3d.scenes.*;
   
    [SWF(width='1440',height='750',frameRate='31')]

    public class spritebg extends Sprite
    {
        private var container:Sprite;
        private var camera:FreeCamera3D;
        private var scene:Scene3D;   
        private var mouseUp:Boolean;
        private var mousePosition:Vertex3D;
       
        public function spritebg()
        {
            ...
           
           
           
           
            stage.addEventListener( MouseEvent.MOUSE_DOWN, mouseDownHandler );
            stage.addEventListener( MouseEvent.MOUSE_UP, mouseUpHandler );
            stage.addEventListener( MouseEvent.MOUSE_MOVE, mouseMoveHandler );
            stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownHandler );
            stage.addEventListener( Event.ENTER_FRAME, enterFrameHandler );
        }
   
        private function enterFrameHandler(event:Event):void
        {
            scene.renderCamera( camera );
        }
       
        private function mouseDownHandler(event:MouseEvent):void
        {
            mouseUp = false;
        }

        private function mouseUpHandler(event:MouseEvent):void
        {
            mousePosition.x = event.stageX;
            mousePosition.x = event.stageY;
            mouseUp = true;
        }      
       
        private function mouseMoveHandler(event:MouseEvent):void
        {
            if( mouseUp )
            {
                camera.rotationY -= (mousePosition.x - event.stageX)*0.10;
                camera.rotationX += (mousePosition.y - event.stageY)*0.10;
                mousePosition.x = event.stageX;
                mousePosition.y = event.stageY;
                /*var startValue:Number = mousePosition.x;
                var finishValue:Number = 200;
                var duration:Number = 1;
                var myTween:Tween = new Tween(mousePosition, "x", Regular.easeIn, startValue, finishValue, duration, true);
                myTween.looping = true;*/
               
            }
        }
       
    }
}


and in my Main FLA i put this :


ActionScript Code:
var sprite1:spritebg = new spritebg();

this.addChild(sprite1);

For some reason when i try running it, it gives me this error:

1180: Call to a possibly undefined method addFrameScript.

How ID Which SWF Calling Class?
Sorry, noobie here. I created a class that is associated with many SWFs. I want to find the file name of which SWF is open. I want to load mp3 files based on which SWF is using the class. Seems like it should be easy, but hours later, I'm stumped. Example: if abc.swf is the swf associated with the class, I want to open abc.mp3 from within the class. I can do the math if I can just find out the file name of the SWF. Help? Thanks.

Calling Constructor In Condition: A Function Call On A Non-function Was Attempted.
Hi guys,

Please help me somebody with this cos I have really no idea. I have made a simply condition calling a constructor of a class. Today I had to add an "else if", what caused the compilator to show me "A function call on a non-function was attempted."...

ActionScript Code:
function loadIt() {    if (var1 == "1") {        var a:SomeClass = new SomeClass(true);    } else if(var2 == "1"){         var a:SomeClass = new SomeClass(false); //<- if this is not here, everything works fine    } else {        var b:SomeOtherClass = new SomeOtherClass();        b.init();    }}

Any ideas? Thanks for any help!

Poco

Function Calling From The _root But Call A Function Within A Instance
I have created a new instance 'Check_1' to work as a checkbox with a set of propertys and functions.

All ive done is created the functions in a script in the first frame of the instance-movie these are...

Simple......
================================================== =======

selected = -1;
function select_frame (FrameNum) {
gotoAndPlay (FrameNum);
}
function change_select () {
select_frame(2);
trace (selected);
}
function change_unselect () {
select_frame(1);
selected = -1;
}

================================================== =======

now from the _root i wish to call the above functions to change the instance propertys, it all works fine from within the instance but i also need to use the functions for that instance from the _root...

iv'e tried the follow with no joy...


_level0.Check_1.change_select()


Any light would be greatly appreciated.

Calling A Parent Class
I'm pretty new to OOP and classes, I have quite some experience in AS1 but I recently started learning OOP. Here's a very 'noobish' question:

Imagion I have a world-class and that class contains a hero-class. So:

_lvl01 -> world -> hero

Now I want a methode in the hero to call a methode in the world, for example when the hero opens a chest this effects the properties of the world. What is the easiest way to do this?

I'm looking for something very simular to _parent when trying to reach back in a movieclips hirarchy. So that in the hero class I can do something like _parent.openChest() were openChest() is a methode in the world class. Hope you get the idea.

Right now when hero is created, I create a _parent property myself in the constructor, being an instance of the world (_root.myWorld), but there's got to be an easier way.

[CS3] Calling An Object From Another Class
I have two classes :
1- JigSaw (MAIN CLASS)
2-FlashCSS (.CSS LOADING HERE)

From JigSaw, i want to use the .css file loaded in an object called "stylesheet",witch is in a function called "completeListener", witch is inside a constructor named "FlaschCSS".

CompleteListener function is called when the.css file has loaded.


PHP Code:




package puzzle
{
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;

    public class JigSaw extends Sprite
    {

        var myTextField:TextField = new TextField;

        public function JigSaw ()
        {


            CreateScene ();
        }
        public function CreateScene ()
        {

            var myTextField:TextField = new TextField;
//HOW DO I CALL THE LOADED STYLE SHEET THATS IN THE STYLESHEET OBJECT?
myTextField.styleSheet=  ???

            myTextField.htmlText = "<p>Jig Saw Puzzle Game</p>";
            addChild (myTextField);


        }








This is the FLASH CSS CLASS :
// It loads an external css file, by itself it works fine.
//I just dont know how to call it from my main class.


PHP Code:




package puzzle
{
    import flash.display.*;
    import flash.text.*;
    import flash.events.*;
    import flash.net.*;
    public class FlashCSS extends Sprite
    {
        public function FlashCSS ( )
        {
            
            var urlLoader:URLLoader = new URLLoader( );
            urlLoader.addEventListener (Event.COMPLETE, completeListener);
            urlLoader.load (new URLRequest("styles.css"));
        }
        private function completeListener (e:Event):void
        {
            var styleSheet:StyleSheet = new StyleSheet( );
            styleSheet.parseCSS (e.target.data);
        }
    }
}








Any tips or clues ?
Thks.

AS3 Calling Java Class
how do i call a java class using AS3? Please help..

Problem Calling Class
Hello,

how is it possible to tell flash that I want to call a class based on a string:

I have classes called "Scene1.as", "Scene2.as", "Scene3.as"... and i want to call them from a class called "Game.as".

the string "_sceneName" contains the name of the class, which could be ex. "Scene2"

what should I do to call the classes based on the string.
scene = new _sceneName(); obviously doesn't work...

Calling Instance Of A Class
So I needed variable instances of a class so I did this:

for (var i:int = 0; i < maxPlayers; i++) {
var thePlayers: player = new player("","");
thePlayers.name = "playerNumber" + i;
addChild(thePlayers);
playerInstances.push(thePlayers);
}

It works but I don't remember how to call each instance up. So what is the syntax to access them? Its been awhile since I have touched actionscript so I am rusty.

Calling Swc Method From .as Class
so i've been given a .swc and i've been told that its got a method on it called doSomething();

for one reason or another i can't include the swf in my fla. what i need to do is somehow include the swc in an AS3 class and then call the swc method therefrom.

so i got it here, in a directory called 'swcs' its called 'someSWC.swc' and i need to import it to someClass.as and call doSomething() on it.

and i have no idea of how i'd do that.......... anyone?

Dynamically Calling A Certain Class
Hey all,
So I have some animated charts I have done up. They live in my library and are linked with the names; "chart1", "chart2", "chart3." If I want to add one of them to the stage based on a selection by a user, how can I create a dynamic name call to the class to add them. Instead of hard coding them, I want to insert the number into the function. For example.

function createNewChart(myChart){
var newChart = new (this["chart"+myChart])()
addChild(newChart);
}

Of course that doesn't work, so I am looking for the syntax to make it work. Ideas?

- B

Calling Different Class Instances
what's the best way for an outside object (say, a button) to call a prototype method inside another class instance? i can do it by calling it directly, like this:


ActionScript Code:
_level0.shape.loadShape(objectNum);


however, i think theres' gotta be a better way to call it--what do you think?

-mojo

Calling Class-functions
I have a problem accessing a memberfunction of a class I made.

Simplified, this is the class:

Code:

class class_ANIMATION {

// Define variables here

// Constructor here

// Member functions here:
function cfn_Play():Void{
trace ("cfn_Play was called");
}
}
This creates the class-instance cl_AVATAR:

Code:

var cl_AVATAR:class_ANIMATION = new class_ANIMATION();
So far so good. Heres where the problem arises - when trying to call the member-function cfn_Play() from the FLA-file:

Code:

cl_AVATAR.cfn_Play();
That should work, right?

AS3 - Calling Get/set Functions Within A Class
ActionScript 3.0, Flash 9 Public Alpha

I'm making use of custom get & set functions within my class. For example:

public function set myProperty( newValue:Number ):void
{
// do custom stuff
_myProperty = newValue;
}

these work beautifully when I call myObjectName.myProperty = 10; from outside my class. However, what if I want to execute this function from within my class without cutting and pasting all of the code redundantly into another internal function? I tried this.myProperty = 10, but it didn't work (it properly changed the value, it just doesn't execute the set function).

Thanks!
~JC

Copyright © 2005-08 www.BigResource.com, All rights reserved