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




Class Method Lag



Hi I have developed this simple class to call any webservice. It works great, but for some weird reason the first time the accessRemote method makes a call it seems to lag for about 3 seconds or so, but any subsequent calls after that are fine.

Can anyone help me?


Code:
class dataload.generateWebService
{

var addEventListener : Function;
var removeEventListener : Function;
var dispatchEvent : Function;
private var WSDL_URL = doStartup._WSDL_URL;
//
public var props : Array;
private var webService;
// public var callBack:Object = new Object();
public var wsdlmethodpc : Object = new Object ();
//Constructor
public function generateWebService ()
{
EventDispatcher.initialize (this);
this.webService = new WebService (WSDL_URL);
this.WSDL_URL = WSDL_URL;
}
public function accessRemote (methodName : String, props : Array)
{
trace ("Pendingcall...")
var wsdlmethodpc : PendingCall = this.webService [methodName].apply (webService, props);
var r = this;
wsdlmethodpc.onResult = function ( result)// or result / response
{
trace ("Passing results to handler...");
r.dispatchEvent (
{
type : 'SOAPRESPONSE', target : this, soapresponse : result
});
}
}
}



Ultrashock Forums > Flash > ActionScript
Posted on: 2008-03-12


View Complete Forum Thread with Replies

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

Call Class Method Inside Another Class.
Hello, I have one class that creates another object from another custom class. Then it calls a method from the newly created class. I want this class to then call a parent's method after it's completed.

Something like this:

PHP Code:



//First Class
class FirstClass{
    function FirstClass(){
        var newClass:SecondClass = new SecondClass();
        newClass.doSometing();
    }
    public function doSomethingAfter():Void{
        // Do this after newClass.doSomethign is done
    }
}

// Second Class
class SecondClass{
    private var _mc:MovieClip;
    private var _incrVar:Number;
    function SecondClass(){
        _mc = _root.createEmptyMovieClip(...);
        _incVar = 0;
    }
    public function doSomthing():Void{
        _mc.onEnterFrame = function():Void{
            _incVar++;
            if(_incVar > 10){
                delete this.onEnterFrame;
                // This is where I would now like to call
                // a method of First Class.. but How?
            }
        }
    }





I know that I could pass the FirstClass object as a parameter to the SecondClass's doSomething function.. but I was wondering if there was another easier way I do not know about to call the parent or calling classes methods. Or maybe there is a way for FirstClass to detect when SecondClass is finished with what it must do before moving on without having to have SecondClass call a FirstClass method?

Thanks!

How Do I Call A Method Of The Document Class From Another Class?
I am creating instances of another class from inside my document class. I want these instances to communicate with the document class, how is this accomplished in AS3?

For example, the document class creates a series of boxes with something like:

var box = new Box();

The document class can now call methods of box with box.method(). The question is how can box call methods within the document class?

Call A Method In A Class That Instantiaded The Class You're In
ok, I have a document class called GameManager()

in GameManager(), I instantiate a class named Map()

in Map() I distribute tiles.

I want mouse events on these tiles to communicate with variables and methods in GameManager() ( and/or MAP() )

I'm having a brainFart on how to do this... any help?

thanx

Delete Instance Of Class From Class' Method
So I have a class called Unit. When I use this class in a .fla file, I create it by saying:

var unit00:Unit = new Unit(...);

So then it creates a gfx representation of the screen for me. I would like to have a method like this:


PHP Code:



public function remove ():Void {   unit_mc.removeMovieClip();   //deleting the gfx representation of the class in the .fla   delete instance of this;   //I want to delete the variable that references the instance of this class} 




So how do I get this to work? I know that delete this will not work when defined inside the class. How do I target the .fla's instance name when I don't know what it will be called?

Thanks for any assistance

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");
}
}

Class Method
Hello Guys,
Hope you doing well...

Please see the attached code....

i've added onPress and onRelease event on a movieClip and when i was trying to use a movieClip (mainButton, circleButton) of this class it show undefined. i've tried with Delegate.create. but not success... :(

please help me.








Attach Code

//code for fla
import Music;
for(var iNum=0;iNum<10;iNum++) {
var mc:MovieClip = this.createEmptyMovieClip("btn"+iNum, this.getNextHighestDepth())
var newMusic:Music = new Music()
newMusic.addToMusic(mc)
}

//code for class
//
import mx.utils.Delegate;
class Music extends MovieClip {

private var mainButton:MovieClip;
private var circleButton:MovieClip;
private var classDepth:Number = 20;

private var text_mc:MovieClip;
private var __smallCircleRadius = 25;
private var popup_mc:MovieClip;
private var __properties:Object = new Object()

function Music() {
//
}

public function addToMusic(mc:MovieClip) {
this.init(mc)
}
function init(mc:MovieClip):Void {
//super.init()
mainButton = mc;
this.createChildren();
}
function createChildren():Void {
circleButton = mainButton.createEmptyMovieClip("circleButton", classDepth++);
this.drawCircle(circleButton, 0, 0, __smallCircleRadius);
//creatign text
text_mc = mainButton.createEmptyMovieClip("text_mc", classDepth++);
text_mc.createTextField("text_txt", classDepth++, 0, 0, 20, 20);
text_mc.text_txt.text = "sample text";
text_mc.text_txt.autoSize = true;
text_mc.text_txt.textColor = 0xd10000;
//adding action
mainButton.onPress = onPressEvent;
mainButton.onRelease = onReleaseEvent;
var xy = this.getRandomXY();
this.setPosition(mainButton, xy.x, xy.y);
}
private function drawCircle(mc:MovieClip, x:Number, y:Number, r:Number):Void {
mc.lineStyle(2, 0xFFCC00, 100);
mc.moveTo(x+r, y);
mc.curveTo(r+x, Math.tan(Math.PI/8)*r+y, Math.sin(Math.PI/4)*r+x, Math.sin(Math.PI/4)*r+y);
mc.curveTo(Math.tan(Math.PI/8)*r+x, r+y, x, r+y);
mc.curveTo(-Math.tan(Math.PI/8)*r+x, r+y, -Math.sin(Math.PI/4)*r+x, Math.sin(Math.PI/4)*r+y);
mc.curveTo(-r+x, Math.tan(Math.PI/8)*r+y, -r+x, y);
mc.curveTo(-r+x, -Math.tan(Math.PI/8)*r+y, -Math.sin(Math.PI/4)*r+x, -Math.sin(Math.PI/4)*r+y);
mc.curveTo(-Math.tan(Math.PI/8)*r+x, -r+y, x, -r+y);
mc.curveTo(Math.tan(Math.PI/8)*r+x, -r+y, Math.sin(Math.PI/4)*r+x, -Math.sin(Math.PI/4)*r+y);
mc.curveTo(r+x, -Math.tan(Math.PI/8)*r+y, r+x, y);
}
private function setPosition(target, xPos:Number, yPos:Number):Void {
var target_mc = target;
target_mc._x = xPos;
target_mc._y = yPos;
}
private function getRandomXY():Object {
var xy:Object = new Object();
xy.x = Math.random()*Stage.width;
xy.y = Math.random()*Stage.height;
return xy;
}
//event
private function onPressEvent() {
this.startDrag();
}
private function onReleaseEvent() {
var newM:Music = new Music()
newM.showDetails()
this.stopDrag();
}
function showDetails() {
trace("Show Details");
trace("can we access mainButton and circleButton from here...")
trace(mainButton + " " + circleButton);

}
}

Extending Xml Class There Is No Method With The Name ...
hey guys... got a question for more of an advanced user... i have a class that extends xml class and i added another simple function there... testme() which just traces a helloworld msg , but when i call it from another class (after i created the object ofcourse) says there is no method with that name... can anyone help? ---> http://pastebin.neod.com/?id=1560

AS 2.0 Class Method Question
hi all,

i have this code to add the class method "isEven" to Math class, that works in any FLA saved in AS 1.0:
code:
Math.isEven=function(num) {
var numout;
if(Math.floor(num/2)==num/2) {numout=true;} else{numout=false;}
return numout;
};


but if i save it in AS 2.0 it does NOT work. how do i get this to work in 2.0?

thanks!

Register Class Method?
Hi..!

I have a MC on the root layer. I want to manipulate this Mc as it was linked in the library(but is not linked). I guess it can be done through the register class method but I dont'n know how... Any sugestions please?
thnx!

AS2 Class: Method Don't See Property
If have a MusicFile class that I'll use to control sound from mp3-file. I work in FAME SDK.


Code:
class game.MusicFile extends game.MusicObject {
private var mp3file:Sound

public function MusicFile () {
}
/*
* loading file (not finished yet)
*/
public function load(mp3fileLocation:String):Void {
TRACE(Flashout.INFO + "mp3 started loading");
var z = scopeRef.createEmptyMovieClip("mp3fileContainer", scopeRef.getNextHighestDepth());
mp3file = new Sound(scopeRef.mp3fileContainer);
TRACE(Flashout.DEBUG + "setting onLoad");
mp3file.onLoad = this.onLoad;
TRACE(Flashout.DEBUG + "onLoad set");
mp3file.loadSound("music.mp3", false);
}
public function startPlay():Void {
TRACE(Flashout.DEBUG + "this is mp3file="+mp3file);
mp3file.start();
TRACE(Flashout.DEBUG + "mp3 playing");
}
private function onLoad(success:Boolean):Void {
var suc = success ? "successfully" : "not successfully";
TRACE(Flashout.DEBUG + "onLoad called. loaded "+suc);
TRACE(Flashout.DEBUG + scopeRef);
if (success) {
TRACE(Flashout.DEBUG + instanceof(this));
TRACE(Flashout.INFO + "mp3file=" + mp3file);
this.startPlay();
} else {
TRACE(Flashout.ERROR + "mp3 not loaded");
}
}
}
When I try to compile it, it traces:

[45:14:786] info: game.Game.Game()
Application started

[45:14:786] info: game.MusicFile.load()
mp3 started loading

[45:14:786] debug: game.MusicFile.load()
setting onLoad

[45:14:786] debug: game.MusicFile.load()
onLoad set

[45:14:997] debug: game.MusicFile.onLoad()
onLoad called. loaded successfully

[45:14:997] debug: game.MusicFile.onLoad()
_level0

[45:14:997] debug: game.MusicFile.onLoad()
undefined

[45:15:007] info: game.MusicFile.onLoad()
mp3file=undefined // what da f#ck???

why this method don't see 'mp3file' property? where am I wrong?

please, help me. work had stuck and I have no idea, how to solve this problem.

AddChild From A Class Method
how do you add stuff to the stage from a class method using addChild?
example:


Code:
package {
public class Example extends MovieClip {
public function Example() {
//...........
addChild(someMC);
}
}
}


what would you do special to do it from a class method, if anything?

Using AddChild From Class Method
how do you add stuff to the stage from a class method using addChild?
example:


Code:
package {
public class Example extends MovieClip {
public function Example() {
//...........
addChild(someMC);
}
}
}


what would you do special to do it from a class method, if anything?

Accessing Class Method
Howdy,

A bit stuck...

So you instantiate a new class like this:
Code:
var myVar:MyClass = new MyClass
And you can then access a method of MyClass like this:
Code:
myVar.myMethod()
But my problem is that I am associating a class with a linked mc in my library and attaching it to the stage at runtime, and I can't work out how to access its methods. There is no 'door' equivillant to myVar in the example above.

Please and Thanks.

Call Class Method From Mc Within In
Hi all

I have this working but my solution seems like a bit of a hack. I'm trying to call the classes methods from a movieclip with the instance of the class


ActionScript Code:
class SearchEngine {
    private var mc:MovieClip;
    function SearchEngine(mc:MovieClip) {
        this.mc = mc;
        //this is the hack
        this.mc.ob = this;
        this.mc.onRelease = function():Void  {
            //what is a better way to call this method
            this.ob.performSearch();
        };
    }
    function performSearch():Void {
        //
    }
}


so is there a better way to target the instance of the class that contains a movieclip from an event of the movieclip?

Thanks in advance

AddChild From Class Method
how do you add stuff to the stage from a class method using addChild?
example:


Code:
package {
public class Example extends MovieClip {
public function Example() {
//...........
addChild(someMC);
}
}
}
what would you do special to do it from a class method, if anything?

Using A Public Class Method
Hi guys

quick question really. I have a Scrollbar class with a public method, arrowPressed(e:MouseEvent), that i'm trying to call from another class, TimelineArea(), using objects with the same name with the lines:

Code:
left_arrow.addEventListener( MouseEvent.MOUSE_DOWN, scrollbar.arrowPressed );
right_arrow.addEventListener( MouseEvent.MOUSE_DOWN, scrollbar.arrowPressed );
note scrollbar is an instance of the Scrollbar class

the method in the Scrollbar class is as follows:

Code:
public function arrowPressed( e:MouseEvent ):void
{
var dir:int = (e.target == left_arrow) ? -1 : 1;
var total:Number = slider.percent + (dir * scrollSpeed);
Tweener.addTween(slider,{percent:total, time:0.5}); // Tweener tween added to add friction to arrow presses - God bless Zeh and chums!
}
The result of this is that both left_arrow and right_arrow in the TimelineArea class give a (e.target == left_arrow) = false result and only move the timeline forward whereas the left_arrow and right_arrow within the Scrollbar class give the correct result: right_arrow = false (moves the timeline +1), left_arrow = true (moves the timeline -1)

why would using the public method externally pass a different result to using it internally, please?

I've included both classes below for context

thanks for your time
a




Scrollbar Class

Code:
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import com.caurina.transitions.*;

public class Scrollbar extends Sprite
{
// elements
protected var slider:Slider;
protected var left_arrow:Sprite;
protected var right_arrow:Sprite;

protected var scrollSpeed:Number = .02;

// read/write percentage value relates directly to the slider
public function get percent():Number { return slider.percent; }
public function set percent( p:Number ):void { slider.percent = p; }

public function Scrollbar()
{
createElements();
}

// executes when the up arrow is pressed
public function arrowPressed( e:MouseEvent ):void
{
var dir:int = (e.target == left_arrow) ? -1 : 1;
var total:Number = slider.percent + (dir * scrollSpeed);
Tweener.addTween(slider,{percent:total, time:0.5}); // Tweener tween added to add friction to arrow presses - God bless Zeh and chums!
}

protected function createElements():void
{
slider = new Slider();

left_arrow = new Sprite();
left_arrow.graphics.beginFill( 0x999999, 1 );
left_arrow.graphics.moveTo(20,0);
left_arrow.graphics.lineTo(20,40);
left_arrow.graphics.lineTo(10,40);
left_arrow.graphics.curveTo(0,40,0,30);
left_arrow.graphics.lineTo(0,10);
left_arrow.graphics.curveTo(0,0,10,0);
left_arrow.graphics.lineTo(20,0);
left_arrow.graphics.endFill();

right_arrow = new Sprite();
right_arrow.graphics.beginFill( 0x999999, 1 );
right_arrow.graphics.lineTo(10,0);
right_arrow.graphics.curveTo(20,0,20,10);
right_arrow.graphics.lineTo(20,30);
right_arrow.graphics.curveTo(20,40,10,40);
right_arrow.graphics.lineTo(0,40);
right_arrow.graphics.lineTo(0,0);
right_arrow.graphics.endFill();

slider.x = left_arrow.width;
right_arrow.x = slider.x + slider.width;

left_arrow.addEventListener( MouseEvent.MOUSE_DOWN, arrowPressed );
right_arrow.addEventListener( MouseEvent.MOUSE_DOWN, arrowPressed );

addChild( slider );
addChild( left_arrow );
addChild( right_arrow );
}


public override function addEventListener( type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false ):void
{
if ( type === SliderEvent.CHANGE )
{
slider.addEventListener( SliderEvent.CHANGE, listener, useCapture, priority, useWeakReference );
return;
}
super.addEventListener( type, listener, useCapture, priority, useWeakReference );
}
public override function removeEventListener( type:String, listener:Function, useCapture:Boolean=false ):void
{
if ( type === SliderEvent.CHANGE )
{
slider.removeEventListener( SliderEvent.CHANGE, listener, useCapture );
return;
}
super.removeEventListener( type, listener, useCapture );
}
}
}
TimelineArea Class (cut down for readability and relevance)

Code:
package
{
//package imports
import flash.display.Sprite;

//scrollbar imports
import com.caurina.transitions.*;
import flash.geom.*;
import flash.events.*;
import com.receptacle.utils.*; // includes SimpleRectangle and SimpleTextField

internal class TimelineArea extends Sprite
{
// class variable declarations
private var cp:CommonProperties;
private var taTitleBarY;
private var taPanelY:uint;
private var taPanelHeight:uint
private var scrollableBase:Sprite;
private var scrollbar:Scrollbar
private var stage_width:uint;
private var stage_height:uint;
private var yearDistance:uint;
private var startYear:int;
private var endYear:int;
private var yearDiv:uint;
private var panelY:uint;
private var panelColour:uint;
private var taTitleBarHeight:uint;
private var nonScrollableBase:Sprite;
private var commonGrey:uint;
private var subheadingFont:String;
private var headingFont:String;

// constructor
public function TimelineArea():void
{
setVars();
initialiseTimelineScrollBar();
addTimelineAreaNavigation();
}

private function setVars()
{
scrollbar = new Scrollbar();
cp = new CommonProperties();
stage_width = cp.stage_width;
stage_height = cp.stage_height;
taTitleBarHeight = cp.taTitleBarHeight;
taTitleBarY = cp.taTitleBarY;
taPanelY = cp.taPanelY;
taPanelHeight = cp.taPanelHeight;
commonGrey = cp.tickColour;
headingFont = cp.headingFont;
subheadingFont = cp.subheadingFont;
yearDistance = cp.yearDistance;
startYear = cp.startYear;
endYear = cp.endYear;
yearDiv = cp.yearDiv;


scrollbar.x = 16;
scrollbar.y = 550-cp.titleBarHeight;
scrollableBase = new Sprite();
nonScrollableBase = new Sprite();
scrollableBase.y = 0;

addChild(scrollableBase);
addChild(nonScrollableBase);
}


private function initialiseTimelineScrollBar():void
{
trace ("Timeline scrollbar initialised");

var scroll_rect:Rectangle = new Rectangle( 0, 0, stage_width, taPanelHeight+taTitleBarHeight+30 );
var sc:ScrollContent = new ScrollContent( scrollableBase, scrollbar, scroll_rect );

addChild( scrollbar );
}


private function addTimelineAreaNavigation():void
{
var left_arrow:SimpleRectangle = new SimpleRectangle(0x000000, 0x000000, 0, 0, stage_width/3, taPanelHeight + taTitleBarHeight);
var right_arrow:SimpleRectangle = new SimpleRectangle(0x000000, 0x000000, (stage_width/3)*2, 0, stage_width/3, taPanelHeight + taTitleBarHeight);

left_arrow.alpha = 0;
right_arrow.alpha = 0;

left_arrow.addEventListener( MouseEvent.MOUSE_DOWN, scrollbar.arrowPressed );
right_arrow.addEventListener( MouseEvent.MOUSE_DOWN, scrollbar.arrowPressed );

addChild(left_arrow);
addChild(right_arrow);
}

}
}

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?

Class And Method Issues
I'm pretty new to classes and OOP, but here it goes:

I have a class that is an extension of the movieclip class, and that has one method called moveMan.

Inside this method, I create an object (called keyLift) that will serve as a key listener for whenever a key is released. When this happens I want the instance of this class to gotoAndStop at a certain frame. Trouble is, I can't call this.gotoAndStop(whatever) because I guess this refers to the keyLift object. Here is the code:


Code:
function moveMan (moveX, moveY, charDirection) {
// some code that really doesn't matter
keyLift = new Object();
keyLift.onKeyUp = function () {
this.isWalking=false;
this.gotoAndStop(charDirection);
};
Key.addListener(keyLift);
}
As you can see, in the lines this.isWalking and this.gotoAndStop I want this. to point to the class instance and not the key listener. Hope that wasn't too confusing, it's 2:30am anyways, better get some sleep.

Cheers!

Add Method To An Existing AS3 Class
Does any one now how I might go about adding a method to flash.display.Graphics so that I can call it just like I would “drawRect()”

for example, “graphics.drawDottedRect()”

I tried extending Graphics with a new class called Graphics and adding my function but this does not work.
I'm sure that the display object is making its graphics instance from the real flash.display.Graphics class and not my extended class.

Any help would be appreciated.

Thanks

Call A Method Outside Its Class
Hi!

In AS2, i built my own EventDispatcher which was able to dispatch events in different classes. When I added an eventListener, the method needed 3 parameters: event, listenerObject, listener

now AS3 got its own EventDispatcher, however, when you add an EventListener, it only requires two arguments: event and a function. But what do I do when I need to call a function that is placed in a other class? Is there no way to call method of other classes with the EventDispatcher Class?

Thanks a lot!

Using AddChild From Class Method
how do you add stuff to the stage from a class method using addChild?
example:



Code:

package {
public class Example extends MovieClip {
public function Example() {
//...........
addChild(someMC);
}
}
}
what would you do special to do it from a class method, if anything?

How To Get The Class Instance Of A Method
Hi guys,

My first post on kirupa.

Is there a way to get the class instance
(meaning "aMenuInstance" inside SomeClass) from the passed method "load"
_scope inside Task should be the "aMenuInstance" from SomeClass.



Code:
public class Task extends EventDispatcher
{
private var _scope:Object;
private var _method:Function;
private var _evt:String;

public function Task(method:Function, evt:String = "")
{
// _scope would need to be _aMenuInstance
_scope = method.some_magical_undocumented_function_or_something;
_method = method;
_evt = evt;
}
.....
}

Code:
public class SomeClass
{
private var _aMenuInstance:SomeMenuClass;

public function SomeClass ()
{
_aMenuInstance = new SomeMenuClass();
var aTask:Task = new Task(_aMenuInstance.load, "menuLoaded");
}
}
any ideas?

AddChild From Class / Method
OKay, what the crap am I doing wrong here:


PHP Code:



package swiftclips 
{
    
    import flash.display.*;
    import flash.text.TextField;
    import flash.text.TextFormat;
    
    trace ("Loaded Status class");

    public class Status extends Sprite {
        
        // Set how many status updates we've made
        public var level:int = -1;
        public var X:int = 15;
        public var Y:int = 5;
        public var Width:int = 300;
        public var Height:int = 30;
        public var loading_image:MovieClip = new Loading;

        public function Request( request:String,tmp_color:String ) {
            
            // Set what level the output will be written to is added to the last one
            level++;
        
            // Create a textbox with the request value in it
            var status_box:TextField = new TextField();  
                status_box.width = Width;
                status_box.height = Height;
        
            // Lets format this up
            var status_format:TextFormat = new TextFormat();
                status_format.font = "Verdana";
                
            // Move out box to the appropriate location            
                status_box.x = X;
                status_box.y = (level * (Height/2) ) + Y;
                status_box.text = " dfsdfdsfd " + request;
            
                // Move out loading image
                loading_image.visible = true;
                loading_image.x = status_box.width + status_box.x;
                loading_image.y = status_box.y;
                addChildAt(loading_image, 0);
                                
                // Color the box
                status_format.color = "0xFF000";
            
            // Apply the format
            //status_box.setTextFormat(status_format);
            
            // Add this to the stage
            this.addChild( status_box );
            
            // Write out a debug message 
            trace("Updated Status: " + request + " @ " + status_box.x + "x" + status_box.y + "px Level " + getChildIndex(status_box));
            
        // function    
        }
//class
}

// package





And on the main stage I call 'er like this:


PHP Code:



// We wanna show what's going on
var Show:Status = new Status;
    Show.Request( "Loading Credentials","0x0066CC" ); 




Everything traces out properly but nothing is added to the stage?

This is all pretty new to me. Plaaass Haallp.

Thanks!

Class And Method Issues
I'm pretty new to classes and OOP, but here it goes:

I have a class that is an extension of the movieclip class, and that has one method called moveMan.

Inside this method, I create an object (called keyLift) that will serve as a key listener for whenever a key is released. When this happens I want the instance of this class to gotoAndStop at a certain frame. Trouble is, I can't call this.gotoAndStop(whatever) because I guess this refers to the keyLift object. Here is the code:


Code:
function moveMan (moveX, moveY, charDirection) {
// some code that really doesn't matter
keyLift = new Object();
keyLift.onKeyUp = function () {
this.isWalking=false;
this.gotoAndStop(charDirection);
};
Key.addListener(keyLift);
}
As you can see, in the lines this.isWalking and this.gotoAndStop I want this. to point to the class instance and not the key listener. Hope that wasn't too confusing, it's 2:30am anyways, better get some sleep.

Cheers!

Help With Targeting A Class' Method From A Button_
I have a class I careated called "View".

Then I created a couple of methods on the class's prototype:


Code:

View.prototype.drawShape = function (numPoints, dups){
//code to draw shapes
}



View.prototype.buildMainMenu = function (){
//code to draw the menu buttons...

//code for the onRelease of the buttons
menu_mc[nm].onRelease = function (){
drawShape(7, 20);
setSectionData(this.id);
}
}

Ok see that On release event? I am trying to call the view class' drawShape method, but i cant figure out how to get it to work. I tried View.drawShape and obviously this.drawShape wont work.

Calling A Method Of A Container Class
Hello there.

I’m writing a class that calls a web Service.

In order to handle the result of the webservice I need an object. This object is declare inside the function that call the webservice.

I want to call a method of the container class from within the onResult method of the object that is handling the webServices result.

How do I do that? If I use the 'this' keyword it refers to the object that has the onResult method.

Here is a code

Class myClass {

Function methodToBeCall() {
//The function code goes here….
}


Function callWebService() {
Var objService = new WebService(url);
Var objResult;

objResult = objService.serviceMethod();
objResult.onResult(result, response) {
//Here is where I want to call the myClass.methodToBeCall();

//The problem is that methodToBeCall is not visible inside the objResult.
//I could achieve this if methodToBeCall is declare as static but I don’t want it to be static.


} //End of onResult

} //End of callWebService


} //End of myClass

Any help will be appreciated.
Thanks

Release Instance Of Class With Method
hello everyone

i have problem with release instance of class with method


Code:
function myClass(){};
myClass.prototype.method = function(){
trace("method");
}
var myInstance = new myClass();
myInstance.method();// method
delete myInstance;
myInstance.metod(); //

the instance has released above



Code:
function myClass(){};
myClass.prototype.method = function(){
trace("method");
}
myClass.prototype.release = function(){
delete this;
}
var myInstance = new myClass();
myInstance.method();// method
myInstance.release();
myInstance.metod();// method

the instance has not released if i use "release" method??

how can i use method delete self of instance??

[help] Custom Class Oop OnRollOver Method
I have a client that I am building an image gallery. There are thumbs and then a custom viewer windo that the thumbs are to send the image location too when they are rolledOVer. The problem is that I do a loader for the fullsize image to load it into cash for each thumb, then scale down the image. Then he wanted it to be black and white images that would go to color when rolled over too.
So I basically have a class that creates a new mc inside of a defined mc. Then inside of that mc I create layers, the lowest is the full sized image that gets scaled down to the black and white image size, the next is a mask layer for it, then after that is the black and white image that doesn't scale down but centers, then there is a mask layer above that.

I can invoke the target_mc.onRollOver = function method, and if I do a trace it will display the info. But if I try to set the thumb movies _visible to false it does not do anything. If i set the _visible to false outside of the onRollover method it makes the black and white photo not visible.

So for some reason when I put the _visible in the target_mc.onRollOver = function method it is not making the black and white image invisible.

Can anyone look at my ImageViewerThumb.as and see what is wrong, it's super script is ImageViewer.as which I will include. Maybe I need to have it extend MovieClip too?


opps, can't attach .as so I will post in in next post

Tremendous Explanation Of A Class And Method
i found this at http://www.mediasparkles.com/2003_09_07_archives.html hope they don't get mad at me for placing it here..... i think is fabulous....

PAY CLOSE ATTENTION TO THE FACT THAT SHE IS TALKING ABOUT TWO SEPERATE FILES (.FLA AND .AS).

All properties and methods are public by default. You don't have to declare them public with the public keyword but you can if you want to spell it out. Private properties and methods, however, have to be declared as such.

When a method is public, it means that it is accessible by the original class and by all instances of that class. When a method is private, it is only accessible by the original class. Below is a class with a private sayHello() method.


Code:
class Hello {
private sayHello() {
trace("hello");
}
}


If you create an instance of the Hello class and then use that instance to call the sayHello() method, you will get an error.


Code:
var greeting:Hello = new Hello();
greeting.sayHello(); // will create an error saying "The member is private and cannot be accessed."


If the sayHello() method was public, you wouldn't get the error. The only class that can access the private sayHello() method is the Hello class itself. Below is an example.

Code:
// Hello.as:
class Hello {
// a private method
private function sayHello() {
trace("hello");
}

// a public method which accesses the private method
function sayHelloAnyway() {
sayHello();
}
}

//separate.fla
var greeting:Hello = new Hello();
gretting.sayHelloAnyway();


The sayHello() method cannot be accessed from outside of this class, including from class instances. But since the public sayHelloAnyway() method calls the private sayHello() method, sayHello() is indirectly available to class instances. The above code results in a "hello" trace in the output window. It does not cause an error.

Private methods are useful for internal processes that you don't need to or don't want to be exposed to the public. I am sure you can think of much better examples than the one above.
posted by Vera Fleischer (9/10/2003 11:07:09 PM);

late

Easeout Using Mx Tween Class Method
hi,
i have text at runtime and i want to scroll it with a easeout effect using mx tween class.
the below link shows exactly what im looking for...the tut does have a fla example but method is not what im after.

http://www.actionscript.org/showMovie.php?id=571

i want to achieve the same using a class method.
can some one guide me where and how to code and include the class code ?

just trying my hand at class methods

this is the code i have for the text at runtime(that's what its called ? )

code:
this.createTextField("mytext", this.getNextHighestDepth(), 200, 10, 300, 100);
mytext.multiline = true;
mytext.wordWrap = true;
mytext.selectable = false;
mytext.text = "Lorem ipsum dolor sit amet, consectetur adipscing elit, sed diam nonnumy eiusmod tempor incidunt ut labore et dolore magna aliquam erat volupat.Et harumd dereud facilis est er expedit distinct. Nam liber a tempor cum soluta nobis eligend optio comque nihil quod a impedit anim id quod maxim placeat.";
var mystyle:TextFormat = new TextFormat();
mystyle.font= "georgia";
mystyle.size = 12;
mystyle.color = 0x990000
mytext.setTextFormat(mystyle);


regards,
Arie

[F8] Pass MC Name As String To Class Method.
I have sort of found a work around but its not exactly what I want so I just wanna check if theres another way.

Check working code below where mc name is not a String(i assume its an object?)


Code:
class myClass{
public function classMethod(obj:MovieClip, val:Number, act:String){
obj[act] = val;
}
}


Code:
import myClass;
var useClass:myClass = new myClass();
useClass.classMethod(mcName, 10, "_x");


Now I wanna pass the mc name as a string to the method but it doesnt work:

Code:
useClass.classMethod("mcName", 10, "_x");


I know I change the class obj type to :String but then the manipulation line will have to look something like _root[obj][act] = val; needless to say I dont like this as if I import the swf thats calling the method into another swf things go screwy cause the mc that im referencing would not lie on the root anymore etc.... Also tried using _level but it didnt work.

[MX] Simple Method/class Problem
This is my first time programming in flash using OOP and i'm trying to do a tetris style game. I'm trying to get my buildmap function to work and it doesn't seem to carry out the method when I call it. Why isn't the function being called? This must be a really simple problem but I'm a noob at this.

Also if my approach seems generally wrong or could be easily improved i'd be greatful for any advice.

Here's the code:


Code:
Game = function(gamewidth, gameheight, gamespeed, gametilesize)
{
Game.prototype.width_across = gamewidth;
Game.prototype.height_up = gameheight;
Game.prototype.speed = gamespeed;
Game.prototype.tilesize = gametilesize;
}
Game.prototype.buildmap = function() {
for(i = 0;i<width_across;i++)
{
for(j = 0;j<height_up;j++)
{
name = "t_"+i+"_"+j;
_root.attachMovie("tile", name,0);
[name]._x = i*tilesize;
[name]._y = j*tilesize;
[name].gotoAndStop(1);
trace("this is working");
}
}
}
_root.realgame = new Game(5,7,2,30);
trace(realgame.height_up);
_root.realgame.buildmap();

Thanks in advance!

Please Help. Class Method Call Question.
If I have a class named "Car".

I then create a new class called "Honda" that extends the Car class.

Is it possible that a method in the Car class can call a method in the Honda class?

I know the Honda class can call Car methods.... but I really need a way to do the reverse.

I tried and it says:
1180: Call to a possibly undefined method myMethodName.

Is it possible?

How Do You Call A Parent Class'es Method?
'->title says it all

how!!?!!?
EDIT-or get a variable in a parent class(no i dont want to declare it with the child), i want to be able to on-demand call it, because it changes.

as in, here is my main code
_______________________________

import MyClass;
var WantThis:int = 7
var myObject:MovieClip
function getWantThis():int{
return WantThis
}

myObject = new MyClass()
addChild(myObject)

_________________________
now this is part of the code of "MyClass"
_________________________

package*bla bla bla...
trace("the value of WantThis in my parent class is "+********************)

_________________________


'->what do i put here so that i can always have an updated value of the variable WantThis, on demand whenever i want to, because it would change!! do i access the variable? or call that method getWantThis??? how do i do either of those!!

thanks for any help!!
**i cant find anything on google :`(

Accessing Method Of Custom Class
I have a custom class that has a setter/getter method called Img it just sets a variable to true or false. I this class is used as a button object. I create several of these objects in a for loop inside a container sprite named container. named Button0-Button5 each button object recieves the same click listener. in this listener I can access the Img method with out a problem using e.currentTarget.Img = true. I have another button just a normal button not from this class. In this button I have tried many ways to access this method with no luck.

trace(container.Button0.isPressed)
trace(container.getChildAt(0).isPressed)
returns error 1119: Access of possibly undefined property isPressed through a reference with static type flash.displayisplayObject

Here is the wierd part
trace(container.getChildAt(0).x ) or trace(container.getChildAt(0).width)
work with out a problem. I dont get why I can access those methods but not my Img method from any where but the object it self

here is the full code http://board.flashkit.com/board/showthread.php?t=786237

Method Calling From Extended Class
Hi all,

I have a Class structure that looks like this:
`Content < BasicMovieClip < MovieClip`
Content extends BasicMovieClip extends MovieClip

myContentMC:Content is on Stage; it has a movieclip inside it (`viewer`).
the `viewer` clip is associated with the BasicMovieClip Class.

The BasicMovieClip Class has a method in it called getMovieClip() in which it should return the instance clip (itself if already on stage, no?)

However, when I run the method, it returns undefined.

Any suggestions?


ActionScript Code:
class Content extends BasicMovieClip
{
     var viewer:MovieClip; // existing clip
     public function Content()
     {
           super();
     }
     public function init()
     {
           var v:MovieClip = this.viewer.getMovieClip();
           trace(v);
     }
}
class BasicMovieClip extends MovieClip
{
     public function BasicMovieClip()
     {
           super();
     }
     public function getMovieClip()
     {
          return (this);
     }
}

Load CSS StyleSheet In Class Method.
Hi,
Im trying to put some css style in textfield of the movieclip throught a class method, but the css style doesnt apply to the textfield. Please, check the code because its a really simple thing, and this is one of those days that simple things doesnt work.

Here is the code.


Code:
dynamic class lib.ContenedorBar {

private var lv:LoadVars;
private var myText:String;
private var myStyle:TextField.StyleSheet;

public function ContenedorBar() {
var _this = this;

this.lv = new LoadVars();
this.myStyle= new TextField.StyleSheet();

this.myTextField.autoSize = true;
this.myTextField.html = true;
this.myTextField.border = true;


this.myStyle.load("xml/bar.css");
this.lv.load("xml/bar.txt");

this.myStyle.onLoad = function(success:Boolean) {
if (success) {
_this.myTextField.styleSheet = this;
}
};

this.lv.onLoad = function(success:Boolean) {
if (success) {
_this.myTextField.htmlText = _this.myText;
}
};
}
}

Flash Can't Override A Method In The Same Class?
in JAVA you can do it.. but not AS 2?

like so.


Code:
class A {
function alert() {
trace("YIKES");
}

function alert(incomming) {
trace(incomming);
}
}
i'm getting this error...
The same member name may not be repeated more than once.

Using Only 1 Optional Parameter In A Class Method
Is it possible to use, say 3rd optional parameter in a built in class method? I'm trying to use the draw method of the Bitmap class with the clipRect parameter only but it says 'type mismatch' probably because I'm not declaring any of the previous optional parameters.

The original method of the bitmap class is the following, and I'm trying to use the bold parameter only:

public draw(source:Object, [matrix:Matrix], [colorTransform:ColorTransform], [blendMode:Object], [clipRect:Rectangle], [smooth:Boolean]) : Void

Any ideas?

SetVolume Method Of The Sound Class...
So does anyone know how come when you attach a sound with code to a new sound object and then you go and try to set the individual volume for that specific sound object using the my_snd.setVolume(num) method.. it seems to change the volume globally of all sounds within the Flash file instead of that particular sound object? I have dug through text and even the Flash8 AS bible states that each sound object is unique and invidiual and to use the setVolume method to adjust it's individual volume level. Is this just a glitch with Flash or something?? Does anyone know how to adjust the volume of individual sounds via code and not through physically placing sounds in MCs or anything?

Using A Public Method From An Imported Class
Hi y'all!

I'm going to try my best at explaining my problem. I'm doing a project that has a jukebox in it that interacts with a list of artists, they are both MovieClips that contain TextFields and Buttons that are controlled by two separate classes: JukeBox.as, Artists.as(for a list) and Artist.as(for each individual artist. I want to access a method from an instance of JukeBox from the Artists (list), so every time I press the name of the artist it sends the id of it to the XML and picks out the mp3 and the info for this artist. Now I'm trying to do this this way. Instances of each class are called from the Main MovieClip:


Code:
/* in Artists.as find instance of JukeBox in Main and put the artists id in the instance */
parent.getChildByName('newJukeBox').findArtist(artist_id);
Yet I get this error:


Code:
1061: Call to a possibly undefined method findArtist through a reference with static type flash.display:DisplayObject.
THe method is defined in JukeBox class and it is public I don't see why it is not working, is there any way around this??? Thanks for all the help you can bring!

EventListener In Class Invoking Method In .fla
Hey all,
I'm just starting in AS3, so forgive my ignorance.

What I'm trying to do is to have a class for dynamically creating units in wargames, the ideas being that this class will be used by multiple games.
However, as each game would have a different result for a particular event, the method associated with that event would need to be in each game's .fla.

For example, I have a Civil War game and a World War 2 game. In the class used by both, there is an addEventListener(MouseEvent.MOUSE_DOWN, checkUnit). In the Civil War game, checkUnit() has the unit check its morale; in the World War 2 game, however, checkUnit() determines the unit's supply.

So, my question is: Can/How does addEventListener located in the Class invoke a method located in an .fla?


Thx

Array Class Splice Method Bug
It seems to be a bug. If not I'd appreciate anyone telling me what the hell is going on with the following snippet.

var firstArray:Array = new Array("a", "b");
var secondArray:Array = new Array("c", "d");

trace(firstArray, " length: ", firstArray.length);
// outputs - a,b length: 2

trace(secondArray, "length: ", secondArray.length);
// outputs - c,d length: 2

firstArray.splice(firstArray.length, 0, secondArray)

trace(firstArray, " length: ", firstArray.length);
// outputs - a,b,c,d length: 3

Why is the firstArray, which has now 4 elements, "a", "b", "c" and "d", reporting it's length as 3? Seems like a bug to me.

Call Method From Mc To Document Class
hello,

I got two problems: first i want to add a mc from the library to the stage.


ActionScript Code:
var wf:mc_workflows = new mc_workflows();
this.addChild(wf);

for some reason flash tells me that mc_workflows is undefined.

lastly i want to call a method within that mc to the main timeline that is the document class. i tried using this.parent.methodsname in the mc but didnt work. any help is much appreciated.

best regards
soutine

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

SetMinutes Method Of Date Class
I want to set the minutes of a date with this code, but it does not work, why?

var testDate:Date;
testDate = Date();
trace(testDate);
testDate.setMinutes(5,0,0)
trace(testDate);

Thanks
Mathias

Custom Class Method Insight
Flash 8
ActionScript 2

Is there a way to make my class visible to the Flash IDE so when I import it I can type in "MyClass." where after the dot I will get a view of methods available in my class like with the use of the Sound class. Where when you declare your var mySound:Sound; and type mySound. it provides a listing of methods available for the Sound Class.

Thanks for looking/responding

Clone Method For 3D Point Class
Hello, I can't work out how to create a temporary copy of a 3D point class on which I'll perform some calculations which I don't want to effect the original.

In C++ it's called deep copying. How do you do it in actionscript?

Any help would be greatly appreciated. I'm going crazy over here!

Here's the class:


Code:
class Point3D {

var origin_x:Number;
var origin_y:Number;

var x_pos:Number;
var y_pos:Number;
var z_pos:Number;

//constructor
function Point3D(a, b, c){
origin_x = 150;
origin_y = 150;

x_pos = a + origin_x;
y_pos = b + origin_y;
z_pos = c;


}

}

Problem With LoadVars In A Class Method
Hi, this is my first post here.

I have been going totally crazy with this problem since yesterday and I hope someone here can help me with this.


I am writing a custom class called diagram and I have a method called readDiagramTextFile() which reads from a text file (path passed as a parameter to the method) and returns a variable read from the text file. I'm using LoadVars for this. Here is the code for the method:


Code:
function readDiagramTextFile(filePath:String):String{
var diagramLV:LoadVars = new LoadVars();
var returnText:String;

diagramLV.onLoad = function(success:Boolean){
if(success){
returnText = this.variableName;
trace(returnText);
} else {
trace("Error while loading the text.");
}
}

diagramLV.load(filePath);

trace(returnText);
return returnText;
}

I want this method to return the value of the variable from the text file. However it is not working as it should. The onLoad() gets executed after the "return" statement, hence the function ends up returning an empty string.

The first trace (inside the onLoad) returns the text I want but the second trace (above the return) gives "undefined".

Is there any way to make sure the load is complete before I return the value? Is this a problem with scope? It's driving me crazy and I have already spent almost 10 hours trying various things getting this to work!

Any help will be greatly appreciated!

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