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




Can't Access Class Member



Anyone have any thoughts on why the loadImage() method of the attached class (SmartImage.as) can't access the class's loadListener property? I have a suspicion that it has something to do with the funky way the object is instantiated (necessitated by the fact that the class is extending MovieClip).Rys



KirupaForum > Flash > Flash 8 (and earlier) > Flash MX 2004
Posted on: 01-03-2007, 05:16 PM


View Complete Forum Thread with Replies

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

How Can Access A Class's Member From An Event Of Member Movieclip ?
Hi,
How can I access sLink at the onPress handler ?

PHP Code:



class CSM {
    private var oMovie4TextField:MovieClip;
    private var sLink; // I would like to access this at the onPress handler
...
...
    public function Initializaton()
    {
         ...
         ...
     this.oMovie4TextField = _root.createEmptyMovieClip('some_mc', _root.getNextHighestDepth());
         ...
        }

        this.oMovie4TextField.onPress = function ()
        {
         ...
         ...
         getURL(this.sLink, "_self"); // not works because this means oMovie4TextField
         ...
        };


Can't Access Class Member
Anyone have any thoughts on why the loadImage() method of the attached class (SmartImage.as) can't access the class's loadListener property? I have a suspicion that it has something to do with the funky way the object is instantiated (necessitated by the fact that the class is extending MovieClip).

Rys

Cannot Access Member Variables In Custom Class
OK, on my main stage I have a MovieClip called mcQuestionManager that is attached to a class called QuestionManager. Inside this MovieClip there are maybe 20 other MovieClips that are called mcQuestion1, mcQuestion2, etc. that are attached to a class called Question. I can't access member variables inside the Questions from QuestionManager. Here are some code samples:

From Question.as


ActionScript Code:
public function set enabled(bDim:Boolean)
{
        trace("i never see this");  //even though I am setting the enabled property below, I never see this trace statement (and none of the actions here ever actually happen)
    var ctDim:ColorTransform = new ColorTransform();
    var transDim:Transform;
   
    if (bDim)
    {
        super.enabled = false;
        ctDim.alphaMultiplier = 0.5;
    }
    else
    {
        super.enabled = true;
        ctDim.alphaMultiplier = 1.0;
    }
       
    transDim = new Transform(this);
    transDim.colorTransform = ctDim;
       
    _bDimmed = bDim;
}
   
public function get enabled():Boolean
{
    return super.enabled;
}

From QuestionManager.as:


ActionScript Code:
private function init():Void
{
    var nQuestions:Number = _arrQuestions.length;
       
    for (var i:Number = 0; i < nQuestions; i++)
    {
        var mcQuestion:Question = _arrQuestions[i];
        var strEndName:String = mcQuestion._name.substring(10, mcQuestion._name.length);
       
                mcQuestion.enabled = false;
        trace (mcQuestion.enabled);  //comes up as undefined
    }
}

Any idea what the problem is? This seems like simple stuff, so I can't imagine why it wouldn't be working...

Class Member Functions Access Problem
Hi All, I have problem with subject .(

The code seems like good, but it doesnt work.

For example:
cmenu.as
class cmenu
{
public var menuitemarray;

public function cmenu{menuitemarray=new Array();}

public function loadxml() {
var omenuitem = new cmenuitem();
this.addmenuitem(omenuitem);
}

public function addmenuitem(omenuitem_param:cmenuitem){
this.menuitemarray.push(omenuitem_param);
}

}

cmenuitem.as
class cmenuitem{}

maintimeline
var omenu = new cmenu();
omenu.loadxml();
--------------------------------------
The addmenuitem doesnt get called , why ?
Are there any notable thing in class member function calling that I dont know ?

PS:I use Flash 8

Thanks in advance.
Csaba

Member Variable Access:flash 8
Hi All,

I have problem with subject.
I got "undefined" message by trace() in 2 cases as well.
I don't understand due to "this.createEmptyMovieClip" gives the newly created empty movieclip as well.

As the code shown below.

class CMedia extends MovieClip{
public var oOwnMovie:MovieClip;

public function CMedia()
{
}


public function LoadMe()
{
trace(this.oOwnMovie) // 1. case : output:undefined
this.oOwnMovie=this.createEmptyMovieClip("mc", this.getNextHighestDepth());
trace(this.oOwnMovie) // 2. case :output:undefined

return 1;
}
}


Very annoying when i can not initialize a public member variable in this simple case.
public var oOwnMovie:MovieClip = new MovieClip; throws error

and I could not initialize it by "createEmptyMovieClip"

Does anyone have example on how can i load external movies by classes ?

Thanks in advance!

Csaba

Root.loaderInfo.parameters And Untyped Member Access
I used to get variables that were added from SWFObject by using _level.variableName. I learned taht I now need to use root.loaderInfo.parameters to access these same varaibles but I am getting a warning message saying that my variable is an untyped member. (warning using FDT in eclipse)

I have tried to cast this using 'root.loaderInfo.parameters.variableName as String' but that isn't working. Can anybody shed some light on this? I'm about ready to turn the warning off but I figure it will be better to understand what is happening and what I can do to fix the warning.

Thanks,
Jason

Creating A Member Of A Class Which Also Is An Mc?
hi.
im making classes to create different things which i mainly draw with the drawing-API.
right now, when i create a member of the class, the constructor gets called, which creates a new mc with the things i want. and to be able to use methods of the class for the mc, i have to target the member of the class, which has a reference to the mc. and when i want to change props like _x and _y of the mc, i have to target it directly instead (unless i make a method for that) and this gets very confusing.

so in short, how can you kind of make an instance of a class, which also is an mc? oh, and i dont want to have to have an mc in the library which links to the class.

any answer apreciated. thanks

AS2 : Using Class Member As ' OnEnterFrame' Listener
Hi folks,

I am having some strange problems to get a class method working properly as function that is hooked up to my roots 'onEnterFrame' event ...

The class member is called but it seems that it is impossible to access the private field members of the class ...

Take a look at this quick example:

(1) External defined class


class TestSteven
{
private var wX:Number;

function TestSteven()
{
wX=0;
}

public function KeyboardHandler(): Void
{
this.wX += 4;
trace("X = "+this.wX);
}
}

(2) In the main movie I instantiate a new object and hook the method of the object to the 'onEnterFrame' ...

import TestSteven;

var mySteven = new TestSteven;

_root.onEnterFrame = mySteven.KeyboardHandler;

(3) So what is the problem? Well the method KeyboardHandler is executed but the private var wX is not availabe and as such the concept does not work ...

Anyone any suggestions or ideas ?

Thx,

Sedas

Loadvars As Class Member Scope
Hi all,

I've declared a class that has a loadvars member and an overloaded function for onLoad. the class also has a different string members. How do I access those members from onLoad??

Code:
class Base{
var m_sConfigFile:String;
var m_aElements:Array;
var m_tfStatus:TextField;
var m_lvInitVars:LoadVars;


function Base(){
}
////////////////////////////////////////////////////////////////////////////////////
function Init(Configs:String):Boolean{
//init text status
m_tfStatus=_root.createTextField("Status",_root.getNextHighestDepth(), 0, 0, 200, 200);
m_tfStatus.autoSize="left";
m_tfStatus.border=true;
m_tfStatus.text="Status";
if(Configs.length==0||arguments.length==0){
m_tfStatus.text="No init file";
return false;
}
else{
m_tfStatus.text="Loading:"+Configs;
m_lvInitVars = new LoadVars();
m_lvInitVars.onLoad=_onLoadInit;
m_lvInitVars.load(Configs);
m_lv
trace(m_lvInitVars._parent);
return true;
}
}
////////////////////////////////////////////////////////////////////////////////////
function _onLoadInit(success:Boolean){

if(success){
m_tfStatus.text="LOAD COMPLETE";
}
else{
m_tfStatus.text="LOAD INCOMPLETE";
}


};
////////////////////////////////////////////////////////////////////////////////////

}

Class Static Member Problem
Hi all

i've a problem as following

static function functionshowLargePic_fun(myPic) {
var loadPic_MCL:MovieClipLoader = new MovieClipLoader();
var loadPic_obj = new Object();
loadPic_obj.onLoadInit = Delegate.create(this,resize_fun);
loadPic_MCL.addListener(loadPic_obj);
loadPic_MCL.loadClip("images/"+myPic,largePic_mc);
}
static function resize_fun() {
trace ("ok")
}

error message

'this' is not accessible from this scope.
loadPic_obj.onLoadInit = Delegate.create(this,resize_fun);


What should i replace it

Thanks in advance
zerolam

Two Objects Of A Class Using The Same Member Array?
I have a class with an array as a member. I declared two objects of the class like this:


Code:
var myNeuronLayer:NeuronLayer=new NeuronLayer(5,3);
trace(myNeuronLayer.neurons.length);

var myNeuronLayer1:NeuronLayer=new NeuronLayer(4,3);
trace(myNeuronLayer1.neurons.length);
The first trace statement outputs a 5, because the first parameter passed to the constructor determines how many elements get inserted into the member array. The second trace statement however outputs a 9. I've tested this with several number combinations and it always holds true that the second trace statement outputs the total of what are supposed to be two separate arrays. The only conclusion I can come to is that the two different objects are using the same array, which doesn't make any sense to me at all. Does anybody know how to prevent this? Or maybe I'm just missing something else?

Here's the code for the class:

Code:
import Neuron;

class NeuronLayer{
//number on neurons in layer
private var numNeurons:Number;
//array of neurons
public var neurons:Array=new Array();
//number of inputs per neuron
private var numInputsPerNeuron:Number;

//constructor
public function NeuronLayer(numOfNeurons:Number,numOfInputsPerNeuron:Number)
{
numNeurons=numOfNeurons;
numInputsPerNeuron=numOfInputsPerNeuron;
for(var i=0;i<numNeurons;i++)
{
var neuron:Neuron=new Neuron(numInputsPerNeuron);
neurons.push(neuron);
trace("Adding Neuron");
}
}

//function to get the num of neurons in layer
public function getNumNeurons():Number
{
return numNeurons;
}

//function to get the num inputs per neuron
public function getNumInputsPerNeuron():Number
{
return numInputsPerNeuron;
}

//function that returns a copy of the neuron array
public function getNeuronArray():Array
{
var neuronArray:Array=new Array();
neuronArray=neurons.slice();
return neuronArray;
}
}

Custom Member Class Question
I have a question you may be able to help answer.

I have a java class, RithUser
it contains another class RithStatus as a member

I have the same structure in Flash.
I know that Openamf returns RithStatus as a member of RithUser on the server but it remains undefined in onResult method. Tried all sorts of stuff, but nothing seems to work.


ActionScript Code:
function onResult(resultObj:ResultEvent):Void {
        trace("INFO LoginCommand::onResultOperation - Using view: "+viewRef);
        // The resultSet is an array but we cannot declare its datatype here
        // because we cannot cast it to Array() due the clash with the
        // Array() global function in Flash (bug/incompatibility with AS1.) 
        //
        // To see this for yourself, uncomment the following line:
        // trace (resultObj.result instanceof Array);
        var resultSet = resultObj.result;
        try {
            if (resultSet.length>1) {
                viewRef.status_txt.text = "There can't be two of you, but there is";
                return;
            }
            for (var i = 0; i<resultSet.length; i++) {
                var n = resultSet[i];
                var un = n["userName"].toString();
                var uid:Number = n["uid"];
                var pos:Number = n["position"];
                var pword:String = n["pword"];
                var rithstat:Object=new Object();
                rithstat = n["rithStatus"];
                trace(rithstat);   // returns undefined
                trace(n["rithStatus"]);// returns undefined
                trace(n["rithStatus"].age);// returns undefined

                var currentStatus:RithStatus = new RithStatus();
               
                currentStatus.setUid(rithstat["uid"]);
                currentStatus.setAge(rithstat["age"]);
                currentStatus.setTimestable(rithstat["timestable"]);
                currentStatus.setAttempts(rithstat["attempts"]);
                currentStatus.setRatio1(rithstat["ratio1"]);
                currentStatus.setRatio2(rithstat["ratio2"]);
                currentStatus.setRatio3(rithstat["ratio3"]);
                currentStatus.setLastUseDate(rithstat["lastUseDate"]);
               
                trace ("age="+currentStatus.getAge());
                //////////////////////////////////////////////////
                var user:RithUser = new RithUser();
                user.setUid(uid);
                user.setUserName(un);
                user.setPosition(pos);
                user.setPword(pword);
                user.setRithStatus(currentStatus);
                trace(un+"  "+uid);
                if (uid>0) {
                    viewRef.loginSuccessful(user);
                }
            }
        } catch (errorObj:Error) {
            viewRef.status_txt.text = errorObj.message;
        }
        trace("INFO LoginCommand::onResultOperation - Got a result!!!!!!!!!!!!: ");
        //viewRef.newPersonList( resultSet );
    }


Any tips ?

Initialize A Member Of Custom Class
Hi All,

I want to initialize the oOwnMovie of CMedia class by this below

....................... code example below
class CMedia extends MovieClip{
public var oOwnMovie:MovieClip;


public function LoadMe()
{
trace(this.oOwnMovie instanceof MovieClip);// output:false
this.oOwnMovie = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
trace(trace(this.oOwnMovie instanceof MovieClip));// output:false again
.....................................

The type checking throws a "false" me.
How can I initialize a class member object in a class function ?

Thanks in advance!
Csaba





























Edited: 12/24/2007 at 05:35:55 AM by strongfrakk

Addressing A Class Member By String
Hi,

Just wondering if there is a way that you could address a member/method/function by using a string. For example, I could call a member of the class MovieClip like this:


Code:
var something:MovieClip = new MovieClip();
something.x = 15;
Is there a way that I can do it like this (I know this code below doesn't work but along these lines is there a way?):


Code:
var something:MovieClip = new MovieClip();
var s:String = "x";

something.s = 15;
icekube12jr

Class Member Passing OnPress Problem
Hi board,

I have a class which controls a movie clip. The movie clip has a button in it. The problem is that I cannot use the class members in the onPress function of the button.


ActionScript Code:
class Controller {  private var id:Number; // I have tried public also  private var myClip:MovieClip; // The clip that has the button    public function Controller() {     // I have got the reference to the MovieClip that contains the    // button.       myClip.myButton.onPress = doSomething;  }  public function doSomething() {      trace(this.id); // <--- does not work. I tried without *this*      // the function is being called so thats not a problem     // Only the *id* is not accessible.  }}


Thanks a lot.

Cruiser.

Class Member Passing OnPress Problem
Hi board,

I have a class which controls a movie clip. The movie clip has a button in it. The problem is that I cannot use the class members in the onPress function of the button.


ActionScript Code:
class Controller {  private var id:Number; // I have tried public also  private var myClip:MovieClip; // The clip that has the button    public function Controller() {     // I have got the reference to the MovieClip that contains the    // button.       myClip.myButton.onPress = doSomething;  }  public function doSomething() {      trace(this.id); // <--- does not work. I tried without *this*      // the function is being called so thats not a problem     // Only the *id* is not accessible.  }}


Thanks a lot.

Cruiser.

Class Question: How To Access Timeline Objects From Class W/o Arguments
Hey all,

I am looking into builiding an application with OO functionality. I understand most of it. Except I cannot figure out how to access something in my app from a class. For instance, lets say I have one Loader class that loads some data and stores it in a variable inside the class (or on the main timeline, doesn't matter). Now, I know I can pass a reference to the data in an argument to another class for that class to manipulate. But if I have several data sources, and other variables and such, that I need to modify in a single class function, how would I do that without having to give the function access to them through arguments? I just want to be able to say, from a class, something like _root.someObject.someFunction();

So, any help would be greatly appreciated, and sorry if that made no sense at all, I tried to explain as best I could.

Happy Holidays!
Dave

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

Button Created Within Class Cannot Access Class Properties
Hi,
I'm using the following code within a class:
code:
_head_mc.attachMovie("headButton", "head_btn", this.getNextHighestDepth());

_head_mc.head_btn.onRelease = function () {
containingClip_mc._parent._parent.clickedHead(_per sonName);
}


The button gets attached (line 1). This works because I can see the mouse changing to a finger.

The onRelease function is declared and works. I know because if I put a trace in there, it works.

The function it calls (containingClip_mc._parent._parent.clickedHead also works, becuase I can see traces from within it.

But the _personName variable is passed as undefined.

I know that this variable has a value, because I can trace it outside the function, but it seems that this onRelease function is not able to see the variable. It's declared as private, but setting it to public doesn't fix anything.

I imagine there's something I don't understand about the scoping of variables. I've tried _parent references, but that doesn't appear to help either. Is there a better way to do this or a workaround?

Barrette

Added by edit
Okay, I've pretty much determined this is a scoping issue. From the onRelease function, I'm unable to access ANY of the functions within my class. I still would like advice on how to do so..

Barrette

How Do I Access A Variable Declared In My Document Class From Another Class
Hi there,

I'm pretty new to classes and am probably missing something really basic so apologies if this seems like a stupid question.

I'm trying to access a variable that I've declared in my document class from within another class.

I know I can pass the variable through when I call the class as follows:


Code:
var myBall:Ball = new Ball(5);
and pick this up in the Ball function within my Ball class as follows:


Code:
public function Ball(ballSpeed) {
trace(ballSpeed);
}
But what if I don't want to do that as I have a whole load of general global variables I want to access which were defined in my document class?

What I actually want to do is just have access to all the variables defined in the document class from within the Ball class.

I tried parent.variableName and various other ways of accessing what I need but all of them spit back errors.

Any help would be really appreciated - I'm sure this is very basic but I'm totally stuck on this.

Many thanks.
Ian

[Embed()] "Class & Member Variables" Error In Flex
The error I'm getting is "Embed is only supported on classes and member variables". I've seen this thrown when the [Embed()] has a semicolon after it, but mine doesn't. Lost as to why I'd be getting this.


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

    public class ImageCropper extends Sprite
    {
        private var image:Image;
       
        [Embed(source='/../assets/library.swf', symbol='reset')] // problem line
        public function ImageCropper():void
        {
            image = new Image('bunny.jpg');
            addChild(image);
        }
    }
}

Have tried embedding the swf without using the symbol attribute, swapping the single quotes with double quotes, and changing the path. (I'm pretty sure the pathing is correct.)

Can anyone see what I'm doing wrong?

Class Functions Not Able To See Other Member Functions/variables?
I am having a problem which has crept up on me a few times now. I am trying to call another member function within the same class, but Flash is unable to recognize it. This also happens when I try to read values of come variables.

For example, here I am trying to set the private boolean member variable to the state of the checkbox.

//NOTE: This is an EventListener. Does this change something major?

private function CheckBoxClick( evt )
{
_enabled = _root["test_sp"].content[_checkBoxName].selected;
trace( _checkBoxName + " checked: " + _root["test_sp"].content[_checkBoxName]._y );
}

This will output the following: "undefined checked: undefined"

Now in the function directly above it, I have the following function:

public function SetYPosition(pos:Number)
{
trace( _checkBoxName );
_root["test_sp"].content[_checkBoxName]._y = pos;
}

And this function will correctly output the checkbox name as well as update the position.

If I try adding the function call "SetYPosition(500);" to the first function (CheckBoxClick), the function will never be called as if Flash cannot see it.

In the past I have avoided this by using the global instance of the class such as _global.settings.function(blah), but the class I am working on now does not have a global instance.

Any ideas? This is really annoying!

Thanks!!!































Edited: 06/27/2007 at 03:30:12 PM by JoMasta

Actionscript Access Class Within A Class
Hey there, well i have 3 files I am working with:

homesite.fla
MainScript.as
AnotherScript.as

In homesite.fla i have

Code:

var main:MainScript = new MainScript ();



in MainScript.as I have

Code:

class MainScript{
public var small_var:Number = 2;
function MainScript(){
}
}



in AnotherScript.as I have

Code:

class AnotherScript extends MovieClip{
function AnotherScript(){
change_setting(10);
}
public function change_setting(numb){
_root.main.small_var = numb;
}
}



the issue i have now, i can edit everything in the "main" variable from within the .fla so if i wanted to change small_var I can do something like:


Code:

main.small_var = 10;



however the issue comes when i try to do that inside another class like in "anotherscript.as" i cannot do it. I am fairly new to actionscript I come from a PHP background, the way i would do it in PHP would be to use a global variable and pass that inside the function, i tried using _root. to see if that would work, but it doesnt really. I did create the variable inside the function, however that would only create one instance used in that function, so that really doesn't help, hoepfully i didn't make this to confusing. Thanks in advance.

Access Class Defined In "linkage..." From External Class
Hi

Rather strange title hu? Well, I'm trying to access a class which was defined on a library symbol in my main.fla by using the Linkage... dialog. Classname: GrungeTitle, BaseClass: BitmapData.

I'm trying to access this class to build my repeating background on my main.fla (which uses a document class: base.as).

My code of the document class:

Code:
public function init():void {
grungeBackgroundTile = new GrungeTile(300, 300);

var spr:Sprite = new Sprite();
spr.graphics.beginBitmapFill(grungeBackgroundTile);
spr.graphics.drawRect(100, 100, 100, 100);
spr.graphics.endFill();

addChild(spr);
}
This code gets called on the third frame of my main.fla by calling: init();
When I try to draw a simple square in the sprite, the rectangle gets drawn on the stage, when I try to make a fill with a library item then it doesn't display a thing.

Any help?
Thanks

Access A Class From Another.
hi,

I created several classes.
I create several instances of theses classes in the main class.

What is the most simple way to call an instance of a class from another class ?

Example :
This is in main.as

ActionScript Code:
var userInstance:User=new User();
var connctionInstance:Connection=new Connection();

In User class I have a login() method that require to use the connection object created in main.as.

Note that this connection object will be unique for the animation. May I declare it as STATIC in the main class ?

What is the proper way to do it ?

I'm missing the Global object of AS2, it was too easy to use !

Access Class With In Sub MC
Hi all

I have import tween class on the first frame
like this

ActionScript Code:
mport mx.transitions.Tween;
import mx.transitions.easing.*;

Now when I put the following code on the same frame it works


ActionScript Code:
var gfBX:Tween  = new  Tween(gf, "blurX", Elastic.easeOut, 5, 5, 1, true);

but if the I put the similar code in side a Movie clip then it doesn't. But if i import the tweens again inside the Movieclip then it works.

So does it means, I have to import tweens multiple times inside the sub movie clips where ever I want to use the tweens.

Thanks

AS3 - Access A MC By It's Class Name
I have a movieclip on the stage with the class name "Yellow". How do I access it in my Document Class? This is what I have so far

Code:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.media.Sound;
import gs.TweenMax;
import gs.easing.*

public class Wheel extends MovieClip
{
var snd1:Sound = new Sound1();
var snd2:Sound = new Sound2();
var snd3:Sound = new Sound3();
var snd4:Sound = new Sound4();

public function Wheel()
{
this.addEventListener(MouseEvent.MOUSE_DOWN, down);
this.addEventListener(MouseEvent.MOUSE_UP, up);
this.buttonMode = true;
}

private function down(event:MouseEvent):void
{
TweenMax.to(this, .15, {glowFilter:{color:0x000000, alpha:.4, blurX:8, blurY:8, inner:true}});
if (Yellow)
{
snd1.play();
}
if (Orange)
{
snd2.play();
}
}

private function up(event:MouseEvent):void
{
TweenMax.to(this, .15, {glowFilter:{color:0x000000, alpha:0, blurX:8, blurY:8, inner:true}});
}
}

}

Access DataGrid From Own Class
Hello guys,

I have the problem to access all methods of a DataGrid instance within my own class.

System: Flash 8, AS2

I have two files:

mp3Player.as
mp3Player.fla

The scene is simple:

Library consists of the DataGrid component and one movie clip. In the movie clip is an instance of the DataGrid component with instance name playList. An instance of the movie clip is placed in the scene and the movie clip has been linked to the mp3Player class in the as file.

The mp3Player class is very simple. It contains a DataGrid variable playList and a constructor to initialize the DataGrid playList in the scene.

What the constructor can do is e.g. playList._visible=false or playList.setStyle(...). But as soon as i start with playList.addColumn or playList.addItem it does not work..

What am I doing wrong?

schnizZzla

Access To Surrounding Class...
Hi there,

I got the following code:


Code:
function playFolder(folder) {
var lv:LoadVars = new LoadVars();
lv.onLoad = function(ok) {
if (this.tracks>0) {
for (var i=1; i<=this.tracks; i++) {
_root.debug=""+(addSong);
addSong(this["track_"+i], this["track_"+i]);
}
start();
}
}
lv.load("http://"+host+"/playlist");
}
addSong and start are methods from the same class as playFolder is in. But I see not possibility to call the addSong from inside this method. this reffers to the loadVars object root referrs to the main timeline.
Can anyone help?

Thank you

Access Movieclip From Another Class
I have a movieclip on the stage "box" - preferences are set to automatically declare stage instances

I can access "box" from the main class, but not from other classes. I know I have to expose "box" so the other classes can see it

and I know it must be simple to do, but I just don't yet know how to do it

Any help greatly appreciated

How To Access MainTimeline From Class
The title says it all, I have a .as class which calls an event function. When the event fires, I'd like the MainTimeline to play... Should be easy no?

Access Class Objects
If i have a parent item that initializes the custom class ObjectTimer. and within ObjectTimer i define an object in the class body with:


ActionScript Code:
public var CloseAPrimary:Object={scaleX:.5,scaleY:.5,time:1,transition:"easeOutElastic", _blur_blurX:100, _blur_blurY:100};

how dould i access a CloseAPrimary in the parent item? I'd like to pass that object to a custom function similar to.

so like foo(CloseAPrimary);

Access Class Functionalities Between Swf
Hi,

I'm starting my first AS3-based website... and I discover how much AS3 questions my day-to-day coding habits.

I'm used to separate the code from the graphics, using a main swf having all the code and launching the visual content produced by the designers. In AS2 I use _global to give access to the main classes or methods, so the designers can use these tools from their "content" swfs without needing the actual code folder at compile time. For example:

In Main class:

ActionScript Code:
_nav:Nav = new Nav();
_global.nav = _nav

In a loaded swf:

ActionScript Code:
_global.nav.changeContent("chapter2.swf");

How can I do the same in AS3? If I try this last code in AS3, I'll have a runtime error saying that the variable _global is not defined...

So is there a way (ideally other than a LocalConnection) to access class functionalities accross several swf, without needing the source of theses classes at compile time?

URLLoader In Class > Access
hello!

i have a class where i fetch some XML data from an external file.
on the main stage, i instantiate the class and call a function to do the external file loading.

my problem now is, that the main stage doesnt know when the loading process is finished. inside the class i do it with the COMPLETE event but i dint know how to wait for that on the main stage so i thought i might return the data in th COMPLETE handler. however, i dont really find the right sntax for that.

can somebody help me with this problem?

here is my code
-------------------------------------------------
package
{
import flash.events.*;
import flash.net.*;


public class Lang
{

private varlangFile = this.loaderInfo.parameters.lang;

public function getVars(folderRoot:String):void {
var xmlURLLoader:URLLoader = new URLLoader();
var xmlURLRequest:URLRequest = new URLRequest(folderRoot + "lang/" + langFile);
xmlURLLoader.load(xmlURLRequest);
xmlURLLoader.addEventListener(Event.COMPLETE , dataLoaded );

function dataLoaded(event:Event):void {
var langVars:XML = new XML (xmlURLLoader.data);
return langVars;
}
}

}
}

How To Access MC By Instance Name From Within A Class?
I have an app that has some display objects already on the stage in the .fla. Let's say I have a text field with the instance name myTitle on the stage. If I want to access that text field (or any other named instance on the stage) from within a class that I'm writing, how do I do so? I would normally just use:

myTitle.text = "new text";

but I don't seem to be able to access instance names this way. I've tried making the class a display object and adding it to the stage/display list to see if that would help, but I have the same problem. How do I go about doing this?

Thanks in advance...

How Do I: Access Instance From Class.
how do i access a movieclip instance in the main FLA file from a class file imported by the main FLA file?

i'd like to addChild() to a movieclip instantiated in the FLA from a class file.

How To Access MC On Stage In A Class?
Hi there.
I have my custom Class, and some movieclips on Stage.
How could I access them from the class?

Let's say, we've got a MC on Stage called "bubble", and example class:

ActionScript Code:
myClass
{
  public function myClass (
    // How I can access "bubble" MC here?
  }
}

How To Access SoundChannel From Different Doc Class ?
I have a loader.swf and a main.swf, in the loader.swf I'm preloader the main.swf and an mp3 file. What I'd like to do is to somehow access the sound channel object from the loader.swf's document class and manipulate it in the main.swf file.

I tried setting up a static getter method but if I do so, then whenever I'm trying something like:


ActionScript Code:
package com.wisebisoft
{
    import com.wisebisoft.loaders.MainLoader;
   
    import flash.display.MovieClip;
    import flash.events.Event;
   
    public class MainClass extends MovieClip
    {
        public function MainClass()
        {
            addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
        }
       
        private function addedToStageHandler(event:Event):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
           
            trace(MainLoader.soundChannelObject);
        }
    }
}
It is throwing errors: type not found... undefined method... but all these from the MainPreloader class... How to solve this?

Because it seems that instead of only checking for my static getter it's running trough all the code and well, since some objects only exist in the MainLoader class, it's normal that it can't find them but why is it even checking them ?

Thanks.

AS 2.0 Can't Access A Variable In My Class
All my variables are set in the top of my class. But undefined if I trace them in my onenterframe function. Why he doesn't read them? What i do?








Attach Code

class clsAlbum {
var dragging:Boolean = false;
var friction:Number = 0.82;
var bounce:Number = 0;
var gravity:Number = 0;
var top:Number = 0;
var left:Number = 0;
var bottom:Number = Stage.height;
var right:Number = Stage.width;
var mvcAlbum:MovieClip;
var vx:Number = 0;
var vy:Number = 0;
var oldX:Number = 0;
var oldY:Number = 0;

function clsAlbum(mvc:MovieClip, object) {
vx = Math.random()*10-5;
vy = Math.random()*10-5;

mvcAlbum = mvc.attachMovie("mvcAlbum", "mvcAlbum"+object.number, mvc.getNextHighestDepth());
mvcAlbum._x = randRange(-10, 200);
mvcAlbum._y = randRange(100, Stage.height-mvcAlbum._height);
mvcAlbum._rotation = randRange(-40, 40);
mvcAlbum.onEnterFrame = function() {
if (!dragging) {
vy += gravity;
vx *= friction;
vy *= friction;
this._x += vx;
this._y += vy;
if (this._x+this._width/2>right) {
this._x = right-this._width/2;
vx *= bounce;
} else if (this._x-this._width/2<left) {
this._x = left+this._width/2;
vx *= bounce;
}
if (this._y+this._height/2>bottom) {
this._y = bottom-this._height/2;
trace(this._y);
vy *= bounce;
} else if (this._y-this._height/2<top) {
this._y = top+this._height/2;
vy *= bounce;
}
} else {
vx = this._x-oldX;
vy = this._y-oldY;
oldX = this._x;
oldY = this._y;
}
};
}
function randRange(min, max):Number {
var randomNum = Math.round(Math.random()*(max-min))+min;
return randomNum;
}
}

Cross-class Access
Just trying to get some fundamental access to properties across classes. Seems like this should be very straight forward!

I have one class (Node) that has a function that creates an instance of another class (Pointer). Node is able to set some properties of Pointer at some times, but at others times is not.

In Node, the Pointer is declared and created here successfully, and successfully prescribes the "hide" value to "true".

public var pointer:Pointer; // (in constructor)

// ADD POINTER ////////////////////////////////////////////////////////////////////////
public function addPointer():void {
pointer = new Pointer({appNode:this, app:app});
pointer.name = "pointer";
pointer.hide = true;
app.container.addChild(pointer);
}

But then when I want to change the value of "hide" to "false", I get an error. "pointer" should be available globally. Why does it appear that it is not?

// DISPLAY POINTER ////////////////////////////////////////////////////////////////////////
public function displayPointer(mode:Boolean) {
pointer.hide = true;
// produces error: 1119: Access of possibly undefined property hide
// through a reference with static type flash.display:DisplayObject
// or pointer.hide = mode;

// this also does not work:

//var rPointer:DisplayObject = app.container.getChildByName("pointer");
//rPointer.hide = false;
}

This is another function in Node that works to remove Pointer. I tried something similar in displayPointer, but it did not work either.

// CLOSE WINDOW ////////////////////////////////////////////////////////////////////////
public function closeWindow():void {
// remove pointer
var rPointer:DisplayObject = app.container.getChildByName("pointer");
app.container.removeChild(rPointer);
// remove window
var rWin:DisplayObject = app.container.getChildByName("window");
app.container.removeChild(rWin);
app.winOpen = false;
}

Access DataGrid Within Own Class
Hello guys,

I have the problem to access all methods of a DataGrid instance within my own class.

System: Flash 8, AS2

I have two files:

mp3Player.as
mp3Player.fla

The scene is simple:

Library consists of the DataGrid component and one movie clip. In the movie clip is an instance of the DataGrid component with instance name playList. An instance of the movie clip is placed in the scene and the movie clip has been linked to the mp3Player class in the as file.

The mp3Player class is very simple. It contains a DataGrid variable playList and a constructor to initialize the DataGrid playList in the scene.

What the constructor can do is e.g. playList._visible=false or playList.setStyle(...). But as soon as i start with playList.addColumn or playList.addItem it does not work..

What am I doing wrong?

schnizZzla

Access Document Class
how to access document class (methods, properties) from an external .swf

Access Data From Another Class?
Hello all --

So I have two classes (classes.XMLLoader) and I am trying to access the xml data from (classes.ActionScripts), but I only get null returned? The loader.Data() of classes.XMLLoader is run before xml/movies.xml has been loaded.



Code:

public function ActionScripts() {

var loader:XMLLoader = new XMLLoader("xml/movies.xml");

trace( loader.Data() ); // null

}

I am sure I will need to use addEventListener, but I have done so without success so far...

Any guidence would be grrrreat!


Thank you,
Jon

AS3 - How To Access A Class Without DisplayObject?
Hello,

I'll "try" to explain as clear as I can...

I've created two classes: ABC and XYZ

The class ABC extends Sprite and I declare it like this:


Code:
for (var i:int=0; i<5; i++) {
var abc:ABC = new ABC();
abc.name = "abc_"+i;
abc.setData(i);
this.addChild(abc);
}
If I want to have access to it, I do something like this:


Code:
for (var j:int=0; j<5; j++) {
trace(ABC(this.getChildByName("abc_"+j)).getData());
}
The class XYZ it's a "standalone" class that does not extends or import any other class, and here it is how I declare it:


Code:
var xyz_01 = new XYZ();
xyz_01.addValue('anyValue');

trace(xyz_01.getValue());
BUT, if I can't figure how to declare it and/or reference to it dynamically.


Code:
for (var i:int=0; i<5; i++) {
this['abc_0'+i] = new XYZ();
this['abc_0'+i].addValue('anyValue');
}

for (var j:int=0; j<5; j++) {
trace(this.getChildByName('abc_0'+j).getValue()); // seems that getChildByName does not work because it the object doesn't have a name and is not added as a child on the stage
trace(this['abc_0'+j].getValue()); // this one only works if I replace the "j" for a "4" (abc_04 was the last one created) otherwise I get "TypeError: Error #1010"
}
So, it could be declared correctlt, but since I can't use their methods I cannot tell, any clues on this?

regards.

Can't Access Number Var In My Class
Hiya, thanks for checking my post. I am really confused as what I am trying to do is so simple!
All I want to do is increment a counter every time a movie loads. I have a method (updateMovie) that is passed an MC and the url of the swf to load into it. My loader listener object then triggers another method that should count the number of movies loaded. For some reason I can't access my counter ('loaded').
If anyone can point out where I am going wrong here I would be really really grateful as I can't understand this at all.
Thanks for any help
Schm

Here is some of the code from within my class:

ActionScript Code:
private var loaded:Number = 0;    //loads passed swf into mc     private function updateMovie(mc:MovieClip, url:String) {        var mclListener:Object = new Object();        mclListener.onLoadInit = mcLoaded(mc);            var image_mcl:MovieClipLoader = new MovieClipLoader();        image_mcl.addListener(mclListener);        image_mcl.loadClip(url,mc);            }    //trigggered when mc is loaded    private function mcLoaded(mc:MovieClip) {        trace("loaded:"+loaded);//traces undefined        trace("mc loadeed:"+mc);                if (loaded<update_ar.length) {            loaded++;            trace("loaded:"+loaded);        }else{            trace("all loaded");        }    }

Access To The Document Class
How can I access the document class from my other classes? Creating a new instance of it seems to be impossible.

Access Class Return Value
OK, this is a follow-up to a recent post (for those who might recognize it).

I'm very confused about what I THINK is probably a simple concept. I want to send a value to a class and use the class's return value. Below is an example, and I want to make sure you understand, THIS IS NOT what I'm actually trying to do -- it's just a very simple example of what I'm not able to do, and if I can answer this question hopefully I can extend the solution to my "real" project.

Here's my AddFour class, which simply adds four to the number I passed to it:

PHP Code:



package { public class AddFour {   private var _num:Number;  public function AddFour(num:Number):void {   _num = num;   init(_num);  }  private function init(_num:Number):Number {   return _num + 4;  } }} 




My problem is, I don't know how to get to the returned value. How do I do that?

To wit: In my .fla file, I have this:


PHP Code:



var foo:AddFour = new AddFour(7); 




If I add a few traces, I see that AddFour successfully adds four to seven to get 11. So far so good.

But what do I do in my .fla file to get a variable whose value is what AddFour returns?

BTW, if I follow the above line in my .fla file with


PHP Code:



trace("foo = " + foo); 




...my trace is...


PHP Code:



foo = [object AddFour] 




This makes sense to me. Again, I assume the answer is pretty simple and I'm just missing something fundamental. What I'm looking for is a line of code that will let me define a variable whose value will be the return value of AddFour. (And PLEASE don't advise me to just do the math in my head. =) )

Thanks!

Access Stage From Class
Hi

I have a package, with classes, functions etc. Basically i need to tell some movieclips on the stage to be visible etc but using this.MyMCName obviously doesn't work. How do i reference movieclips from within a class?

Access Other Class' Variables
Hello Everyone,

I am making a tileMap class which copies bitmapdata from one location to another. I am storing all my tile-sheets as static bitmapdata objects in an Assets class. Would it be faster/ better practice to copy the tile-sheet I am using to the tileMap class instead of referencing the assets class multiple times every frame? Also the map array which stores the tile reference is stored as a static property in a map class, could I achieve better performance by duplicating this array in the tileMap class?

Thanks

Spir

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