Accessing Varibles In A Class From An Event
Here is my first OOP Actionscript.... just doing a quick loading script and i'm having problem accessing one of the private variables from an event handler
Code:
/* FRAME 1 */
#include "Arrays.as"
var global_loader:Load = new Load();
/* LOAD.AS */
class Load {
private var _totalPercentage:Number = 0;
private var _totalLoads:Number = 0;
private var _movieClipLoader:Object;
private var _movieClipTargets:Array;
private var i:Number;
public function Load() {
// each time a new class or load function is called we increment the counter
this._movieClipLoader = new MovieClipLoader();
this._movieClipTargets = new Array();
this._movieClipLoader.onLoadProgress = function(movieClip:Object, loadedBytes, totalBytes) {
movieClip["amount_loaded"] = loadedBytes/totalBytes
};
this._movieClipLoader.onLoadComplete = function(movieClip:Object) {
// THIS WILL HAVE TO DO UNTIL WE FIGURE IT OUT
// THIS IS WHERE THE TROUBLE STARTS
trace(this._movieClipTargets) // <--- I WANT TO USE THIS VARIABLE
_root.global_loader.removeClip(movieClip); // <---- THIS WORKS BUT IS STUPID !!!!
this._movieClipTargets.removeUnique(movieClip); // <-- THIS IS WHAT I REALLY WANT TO DO
_root.global_loader.removeClip(movieClip);
};
}
public function removeClip(movieClip:Object) { // <---- I SHOULDNT NEED THIS FUNCTION
trace("remove clip called");
this._movieClipTargets.removeUnique(movieClip);
trace(this._movieClipTargets)
}
public function addItem(fileURL:String, movieClip:Object) {
// each time a new class or load function is called we increment the counter
this._movieClipLoader.loadClip(fileURL, movieClip);
this._movieClipTargets.pushUnique(movieClip);
trace(this._movieClipTargets)
this._totalLoads++;
}
public function removeItem() {
// each time a new class or load function is called we decrement the counter
this._totalLoads--;
}
public function get movieClipTargets():Object {
return this._movieClipTargets;
}
public function set movieClipTargets(value:Array):Void {
this._movieClipTargets = value;
}
public function get totalPercentage():Number {
// this is where we calculate everything
this._totalPercentage = 0;
for(i = 0; i < this._movieClipTargets.length; i++) {
this._totalPercentage = this._totalPercentage + this._movieClipTargets[i]["amount_loaded"];
}
this._totalPercentage = Math.round((this._totalPercentage / this._movieClipTargets.length)*100)
if(isNaN(this._totalPercentage)) {
// not loading
this._totalPercentage = 100;
}
return this._totalPercentage;
}
public function set totalPercentage(value:Number):Void {
this._totalPercentage = value;
}
public function get totalLoads():Number {
return this._totalLoads;
}
public function set totalLoads(value:Number):Void {
this._totalLoads = value;
}
}
What is the best way to get the variable _movieClipTargets from the onlLoadComplete handeler?????
Thaniks anyone for help on this one... feeling stuck and stupid!
Andre
ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 10-19-2006, 02:27 AM
View Complete Forum Thread with Replies
Sponsored Links:
Accessing Event Listeners In Custom Class
I'm building a movie and using custom classes for the first time. I've built a custom class and linked a movie clip in my movie to it so that the color of the text in the clip will change when it is rolled over. I have 10 instances of this movie clip in the movie, so it saves me a lot of code. Instead of writing 10 event listeners for ROLL_OVER and 10 more for ROLL_OUT (as I would have done in the past), one for each instance of the movie clip on the stage, I've now written the event listeners and corresponding functions into the custom class. So far, so good, it all works great. When I roll over and out on any of the 10 instances of the movie clip on the stage it changes color. See attached code.
However, depending on what is going on in the movie I sometimes need to disable the event listeners on one or more movie clips. So I've written code in the movie itself to remove the event listeners from the instance of the movie clip that I need to disable. See attached code.
But, alas, it doesn't work.
I get this error:
ReferenceError: Error #1065: Variable turnWhite is not defined.
I thought that by making the method "public" in the custom class I would be able to call it from the movie, but I guess not. Any help or guidance would be greatly appreciated. Thank you very much.
Attach Code
public function MusicPlayer() {
this.addEventListener(MouseEvent.ROLL_OVER, turnWhite);
this.addEventListener(MouseEvent.ROLL_OUT, turnBlack);
_myTextFormatNormal.color = 0x6ABAB1;
_myTextFormatOver.color = 0xDA4535;
this.myText.setTextFormat(_myTextFormatNormal);
this.mouseChildren = false;
this.buttonMode = true;
}
/* create the first custom function of the class */
public function turnWhite(event:MouseEvent):void {
this.myText.setTextFormat(_myTextFormatOver);
}
public function turnBlack(event:MouseEvent):void {
this.myText.setTextFormat(_myTextFormatNormal);
}
View Replies !
View Related
Assigning / Accessing Componet Varibles
If i have a componet defined. It carries the varible "name"
Now i've placed an instance of the componet on the scene and called it wrapper.
How would i set the value of name?
I've tried wrapper.name = "myName" but this dosent seem to work?
Or on the flip side
If in frame 1 I've crated a variable called rootName. How can the instance of wrapper access rootName?
Thanks in advance.
Jesse
View Replies !
View Related
Accessing A Dynamic Text Field In A Class Other Than The Primary Class
I have tried to read and understand some of the other threads for this issue but, I think it would be easier to understand if I show my specific issue. I left some code out to make my issue more clear.
Alpha is the primary class with access to the stage. If I write the event listener and function contained in the Bravo function into the Alpha function it works. Although, I want it to be in a different class in the same package (such as the Bravo class).
I have created a instance of a class which is a physical object on the stage (lets say it's a card). The event listener is in the instance so that each instance has a self contained listener.
The bottom line is it works in the primary class but in no others. How can I make it access the text field (so when I click on the "card" the text field shows "something"?
ActionScript Code:
package a {
public class Alpha {
public function Alpha() {
x:Bravo = new Bravo();
}
}
}
package a {
public class Bravo {
public function Bravo() {
this.addEventListener(MouseEvent:CLICK, clickEvt);
function clickEvt(event:MouseEvent) {
<MovieClip>.<MovieClip>.<DynamicTextField>.text = "something";
}
}
}
}
View Replies !
View Related
Tough One: Accessing Class Methodes From Other Class Files
Tough question for the experts...
In my classfile class Classes.tools.depthManager, I've got a static methode
Code:
public static function getLoopDepth():Number {
In another classfile Classes.tools.frameRateViewer, I want to access that methode
Code:
var tempDepth = Classes.tools.depthManager.getLoopDepth();
The compiler claims: "There is no class or package with the name 'Classes.tools.depthManager' found in package 'Classes.tools'."
So I tried writing import Classes.tools.* at the top of my Classes.tools.frameRateViewer.as, hoping I could just write
Code:
var tempDepth =depthManager.getLoopDepth();
But there the compiler claims: "The class being compiled, 'Classes.tools.depthManager', does not match the class that was imported, 'depthManager'."
I'm sure the Classes.tools.depthManager.as works fine: I can call the static depthManager.getLoopDepth() from a button in the fla file...
Any ideas? Thanks!
View Replies !
View Related
Accessing Document Class From Static Class?
I am building a family tree like tree in flash.
I have a package TreeManager which holds all my classes.
The document class TreeManaager.Tree controls adding new nodes to the stage.
ActionScript Code:
public function addProfile(relationship:Object):void
{
profile = new Profile();// create new profile
var align:Alignment = new Alignment();//make Alignment object
...
The profile class controls all the internal node functionality.
Question - If I have a button in my node MC (profile class) which should add a new relationship (i.e. call addProfile) how to I do this?
ActionScript Code:
public class Profile extends MovieClip {
public function Profile ():cool:
{
this.addEventListener(MouseEvent.CLICK,Tree.addProfile);
This always throws an error. I can just add the buttons events from the document class, but it would be helpful to know if you can access the document class from a packaged static class?
ActionScript Code:
// add button events
profile.mother.addEventListener(MouseEvent.CLICK,addRelationship);
profile.brother.addEventListener(MouseEvent.CLICK,addRelationship);
profile.son.addEventListener(MouseEvent.CLICK,addRelationship);
View Replies !
View Related
Accessing A Variable From An Event
Hi all:
I'm trying to access a variable from an on(rollOver) event.
On frame 1 of my main timeline, I have trace(where);
Here's the code:
ActionScript Code:
on(rollOver) {
_global.where = "musicOn";
}
Forgive me if this is a newbie question. Basically, I want to keep track of which buttons I've rolled over.
Thanks,
Frankie
View Replies !
View Related
Accessing Functions In A Class, From Another Class?
is this possible?
for instance, i have a function called "registerThumb" in my main engine class which keeps a delegated array of items.
However the only time i want to call that function, is from within another class which creates the thumbnails "Thumb.as", so i can automatically register paths into the array instead of just names.
does that make any sense?
View Replies !
View Related
Child Class Trigger Event For Parent Class
is there a way for a parent class to listen to a variable in a subclass, and when it changes, run a function?
This seems like a pretty simple thing to do. I'm trying to keep my subclass independent of my main class, so i just have a variable that is set to false, and when its finished, it sets the variable to true.
The only thing i can think of is having an onEnterFrame that keeps checking the variable...but it seems like an event would be more efficient.
thanks!
View Replies !
View Related
Why Is An Event On One Class Object Being Broadcast For All Instances Of That Class?
I have a custom class called McText which extends MovieClip, and includes an input text field. That class has a function to register itself as a listener to Key - Key.addListener(this). It does not register by default.
There are multiple instances of McText. But even though I only call the function to register on one of those instances, ALL of them fire an onKeyDown function when i type into their text field, regardless of whether i've registered that particular object to Key or not. I register one, I register them all.
This is a little annoying because I use this class everywhere, and I want to be able to assign an onKeyDown function for only one of them. At first i tried writing that function outside of the class itself, as in:
classObject.onKeyDown = function()
But that, perhaps unsurprisingly, created an onKeyDown function for every instance again.
I thought to myself "I know, I'll register McText with Key by default (in the constructor), write an McText.onKeyDown function in the class itself, and then get that function to use a broadcaster". The idea being that onKeyDown will fire on all of them, but the broadcaster will be registered to a specific listener on an object by object basis.
So I did that, and created a function to register a broadcaster listener. I then created a broadcaster listener in a seperate, different, class, throw it to the McText function so it registers with its broadcaster and guess what? Now that listener receives an event from every instance of that class.
There's no explicit use of static vars or functions anywhere.
Sorry for the long question, but can anyone enlighten me as to what's going on? You get virtual chocolate if you do
View Replies !
View Related
How Do You Listen In One Class For A Custom Event Dispatched From Another Class?
I am not sure how to word this, so here is what I would like to happen:
MyDocumentClass contains an instance of MyItem and MyItemManager. MyItem will fire an ItemEvent.ITEM_CHANGED event. I want MyItemManager to listen and react to that event. Possible? Here's my code:
ItemEvent.as:
ActionScript Code:
package
{
import flash.events.Event;
public class ItemEvent extends Event
{
public static const ITEM_EVENT:String = "itemEvent";
public function ItemEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false)
{
super(type, true);
}
public override function clone():Event
{
return new ItemEvent(type);
}
public override function toString():String
{
return formatToString("ItemEvent", "type", "bubbles", "cancelable");
}
}
}
MyDocumentClass.as:
ActionScript Code:
package {
import flash.display.Sprite;
import MyItem;
import MyItemManager;
public class MyDocumentClass extends Sprite
{
public var item:MyItem;
public var manager:MyItemManager;
public function MyDocumentClass()
{
item = new MyItem();
manager = new MyItemManager();
item.dispatchCustomEvent();
}
}
}
MyItem.as:
ActionScript Code:
package
{
import flash.display.Sprite;
import flash.events.EventDispatcher;
import ItemEvent;
public class MyItem extends Sprite
{
public function MyItem()
{
}
public function dispatchCustomEvent():void
{
dispatchEvent(new ItemEvent(ItemEvent.ITEM_EVENT));
}
}
}
MyItemManager.as:
ActionScript Code:
package
{
import flash.display.Sprite;
import ItemEvent;
import flash.events.EventDispatcher;
public class MyItemManager extends Sprite
{
public function MyItemManager()
{
addEventListener(ItemEvent.ITEM_EVENT, handleItemEvent);
}
public function handleItemEvent(e:ItemEvent):void
{
// do something here
}
}
}
View Replies !
View Related
Accessing The Parent Of An Event Listener
i don't entirely know if the event listener is the child of the object it's listening on so i'm a little confuzzled.
CODE:
SPRITE.addEventListener(Event.ENTER_FRAME, dothis);
function dothis(e:Event)
{
trace(this.x);
}
produces nothing so i figure the this is referencing the enterframe listener. is it possible to reference the SPRITE with a "this"... this.eventparent.x or something like that.
View Replies !
View Related
Accessing The Parent Of Event Listener
i don't entirely know if the event listener is the child of the object it's listening on so i'm a little confuzzled.
CODE:
SPRITE.addEventListener(Event.ENTER_FRAME, dothis);
function dothis(e:Event)
{
trace(this.x);
}
produces nothing so i figure the this is referencing the enterframe listener. is it possible to reference the SPRITE with a "this"... this.eventparent.x or something like that.
View Replies !
View Related
Accessing An Event.COMPLETE Listener
I'm having problems accessing a Event.COMPLETE listener for loading a php file:
Code:
function prepareD(){
//more code before
var hsloader:URLLoader = new URLLoader();
hsloader.dataFormat = URLLoaderDataFormat.VARIABLES;
hsloader.addEventListener(Event.COMPLETE, highSdata);
hsloader.load(myData);
//more code after
}
function highSdata(evt:Event){
if(evt.target.data.highS<(Math.round(musicC/musicL*100))) {
//code
}
}
What is happening is I'm creating a new URLloader, then loading the php, and I create a Event.COMPLETE listener, but when the load completes (I've tested with navigateToURL), the listener doesn't trigger. I've also tried putting the var before functions, but it doesn't work either... Any ideas?
Thanks!
View Replies !
View Related
External Varibles, Pathing Varibles, Targeting Variables OMG I HATE VARIABLES
I'm making a movie.
this is the idea. 5 buttons - identical - all text based - basically they're MCs, with the instance state changed to 'button'.
on clicking, each button will open a new window, loading a URL. (this is the easy part)
the text on each button is dynamic and contains 2 text fields.
the first text field is the title.
the second text field is the descrition.
so you have 5 indentical buttons, each will have a title=description.
each title, and each descrition is a variable called from a text file. (eg, title1, title2, title3, desc1, desc2, desc3 etc).
now I can make 5 different MCs, each containing 10 dynamic txt fields, each of which calls a specific variable, but I don't want to hard-code.
Any ideas on how I can do what I want to?
http://www.7inone.info/dls.swf
this is a static version of what I want. I'm gonna upload it in a minute.
thanks in advance
sid.
View Replies !
View Related
Event.INIT, Accessing Parent Variables From Loader?
ActionScript Code:
public function loadPic (m:MovieClip, s:String, i:String) { var url:String = "images/"+s+"/"+i+".jpg"; trace (url); // var loader:Loader = new Loader(); configureListeners (loader.contentLoaderInfo); var request:URLRequest = new URLRequest(url); loader.load (request); loader.x=loader.y=13; m.addChild (loader); } private function configureListeners (dispatcher:IEventDispatcher):void { dispatcher.addEventListener (Event.INIT, initHandler); } private function initHandler (event:Event):void { //trace ("initHandler: " + event); }
in the above code. i am trying to access the m variable from the loadPic function in the initHandler function. The loader is the child of the m mc.
This class is being called in a loop in which im loading a list of thumbnail jpegs. This loader is attacehd to each one of the movieclips that the jpegs are getting loaded into.
once the jpg is loaded (initHanlder) i need to remove the loading graphic that is in each of the container movie clips. i can't access anything from that initHandler.
ie event.target.parent. it doesn't work.
--
how can i remove that loader graphic on init?
--
movie clip
- loader graphic named lg_mc
- loader class with listeners
View Replies !
View Related
Accessing Class With Loadmovienum...
HI,
I need to build a project that will have a main.swf calling many other swf. I don't want to have to rebuild my main swf every time I change a line of code so that's why I want to have one swf that will contain all my classes(objects). So lets say I have in class.swf:
Test=function()
{
this.x=5;
this.y=7;
}
If I use loadMovieNum("class.swf",1)in call.swf, can I instantiate this?????
inst=new Test(); //doesn't work
inst=new _level1.Test();//doesn't work
Anyone have a clue?????
Thanks
View Replies !
View Related
Accessing Movieclip From Within A Class
Hi I have a class on frame 1 called VTODVideo. Inside that I have a cuePoint handler which fires this when I reach a cuepoint:
code:
private function cuePointHandler(e:MetadataEvent):void
{
//trace(e.info.time);//time cuepoint was set
trace(e.info.name);//name of cuepoint
var q:VTODQuestion = new VTODQuestion(e.info.parameters.id);
}
At the time of the cue point, I create a VTODQuestion class. I am having problems accessing movieclips from within the Question class. I have a movieclip on the root of my stage named "fader" and I just want it to fade in when a question class gets instantiated. Here is my question class:
code:
package com.dop
{
import flash.display.MovieClip;
import gs.TweenLite;
import gs.easing.*;
public class VTODQuestion
{
public function VTODQuestion(questionNumber:Number)
{
trace("question number: " + questionNumber);
TweenLite.to((this.parent as MovieClip).fader,1,{alpha:1});
}
}
}
I am getting this error:
Code:
1119: Access of possibly undefined property parent through a reference with static type com.dop:VTODQuestion.
Ive tried this.parent.parent as well and no luck
View Replies !
View Related
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.
View Replies !
View Related
Accessing Custom Class In Fla
Hello,
I seem to be the opposite of most of you. I am a long time object oriented programmer, but am VERY new to Flash. I hope this questions is not too basic, but I am having a heck of a time getting this to work.
I have a class written in ActionScript 3 (Flash cs3) in an .as file as follows:
package foo
{
public class bar{
private id:Number;
public function bar( barID:Number){
id = barID;
}
public function getID():Number{
return id;
}
}
}
It doesnt get much simpler than that i dont think.
I saved that in a projects directory in foo/bar and named the file bar.as
Then I did a file new fla (AS3) file which I saved to the same dir as the .as file, I opened the actionscript panel and I type the following:
var myBar:foo.Bar = new foo.Bar();
It chokes on that line because it cant seem to find my class. I get the error, "Type was not found or was not a compile-time constant: Foo". I even tried an import line, but it chokes on that, it just doesnt see my class. I tried also messing with the classpath stuff, but I can not seem to get this to compile.
What am I doing wrong?
Thanks,
-Savij
View Replies !
View Related
Accessing Functions From Doc Class?
Hey all,
Ive been tryint to use getter/setter methods on my doc class, but i just cant get it to work.
here is my doc class Main.as:
ActionScript Code:
package
{
import flash.display.*;
public class Main extends MovieClip
{
function Main()
{
}
function getTest()
{
trace("got");
}
}
}
What do i add to this class to be a ble to access it?
Player.as:
ActionScript Code:
package
{
import flash.display.*;
public class Player extends MovieClip
{
function Player()
{
//something.getTest(); ?
}
}
}
Thanks for helping,
Gareth
View Replies !
View Related
[OO] Accessing Parent Class...
I'm having some problems accessing a parent class with my Flash app.
My class hierarchy goes like this: I have a GameController class which contains an instance of my TeamManager class. The TeamManager class contains an array of pointers (TeamList) to different TeamMember instances.
In my TeamMember class I've set a mouse event:
PHP Code:
public function TeamMember() { this.addEventListener(MouseEvent.MOUSE_DOWN, Select);}public function Select(event:MouseEvent):void { Selected = true; }
The problem here is that once one TeamMember is selected, I want to deselect all other TeamMembers listed in TeamManager's TeamList array. I created a method in TeamManager (DeselectAll) but I can't for the life of me find a way to call it from the Select method in the TeamMember class.
View Replies !
View Related
Accessing Variables From Another Class
I'm new to working with multiple classes, so be gentle. I have a doc class and one other class (Input.as). I want to access a variable from Input in my doc class. I've imported the class successfully, but can't seem to access the variable. I thought I would just need to access that var by something like Input.strNum but get this error:
1119: Access of possibly undefined property strNum through a reference with static type Class.
View Replies !
View Related
Accessing Movieclip From Within A Class
Hi I have a class on frame 1 called VTODVideo. Inside that I have a cuePoint handler which fires this when I reach a cuepoint:
ActionScript Code:
private function cuePointHandler(e:MetadataEvent):void
{
//trace(e.info.time);//time cuepoint was set
trace(e.info.name);//name of cuepoint
var q:VTODQuestion = new VTODQuestion(e.info.parameters.id);
}
At the time of the cue point, I create a VTODQuestion class. I am having problems accessing movieclips from within the Question class. I have a movieclip on the root of my stage named "fader" and I just want it to fade in when a question class gets instantiated. Here is my question class:
ActionScript Code:
package com.dop
{
import flash.display.MovieClip;
import gs.TweenLite;
import gs.easing.*;
public class VTODQuestion
{
public function VTODQuestion(questionNumber:Number)
{
trace("question number: " + questionNumber);
TweenLite.to((this.parent as MovieClip).fader,1,{alpha:1});
}
}
}
I am getting this error:
Code:
1119: Access of possibly undefined property parent through a reference with static type com.dop:VTODQuestion.
Ive tried this.parent.parent as well and no luck
View Replies !
View Related
Accessing Data In A Class
Hey guys,
This question is hopefully simple. I have a class that loads an XML document and places it into an XML object. Does anyone know why I can't access that XML object from the XML that instantiates the class? I have a getter but it gets nothing. If I trace the XML object in the class it shows the XML but when I try to get it, it is blank....stumped.
Thanks.
View Replies !
View Related
AS2 Accessing Class Methods
Hi guys,
i created custom classes for a quiz flash im making...
in these custom classes i also attachMovie with class references
thus i have the following class hierarchy
quote:
Movie 1/Class 1
|- Movie 2/Class 2 (attachMovie)
|--Movie 3/Class 3(attachMovie)
now i have a scenario in that Class 3 needs to execute a function of class 2
So what i did is assign a variable to movie 3 with a reference in movie 2
thus in movie clip 2 when im attaching the movie clip 3 i have quote:var movie2.self = this; and movie3.clip = self;
now when im running the code and while i can
quote:
trace(clip) // outputs movie2
in movie 3
i cant seem to
[Qe]
clip.function(param);
heres a snippet of the code
Any idea whats happening here?
Attach Code
// Movie 3/ Class 3
function checkAnswer(no:Number) {
var pts:Number = getAnswer(no).pts;
if (no == correctAnswerObj.ansNo) {
pts = correctAnswerObj.pts;
}
trace(levelMc.pts); // outputs the variable's value successfully.
levelMc.updateLevel(pts); // levelMc is movie 2 with the class 2 function 'updateLevel'
// clearQuestion();
}
// Movie 2/ Class 2
function upateLevel(pts:Number):Void {
trace('ok: '+pts); // its not executing
var allAsked:Boolean = false;
var wrong:Boolean = false;
var passedLevel:Boolean = false;
if (pts == 0) {
questionsWrong++;
trace("wrong answer");
}
if ((allAsked=(noQuestion>askNoQuestions)) || ((allowedWrong != undefined) && (wrong=(questionsWrong>=allowedWrong)))) {
trace("level over");
if (allAsked) {
trace("all questions asked");
if (levelPts>totalPts) {
trace("proceed to next round");
passedLevel = true;
} else {
trace("you failed to pass this level");
}
}
if (wrong) {
trace("You got "+questionsWrong+" answers wrong");
trace("you failed to pass this level.");
passedLevel = false;
}
if (grades) {
var rank:String = undefined;
for (var i:Number = 0; i<grades.length; i++) {
if ((pts>=grades[i]['min']) && (pts<=grades[i]['max'])) {
rank = grades[i]['gradeName'];
break;
}
}
trace("Your points make you:- "+rank);
}
quiz.updateQuiz(pts,passedLevel);
} else {
trace("ready for next question");
getNextQuestion();
}
trace("level points: "+levelPts);
}
View Replies !
View Related
Accessing MC From External Class
Hi all. I'm just learning about external classes, so please be gentle.
I want to access a movieclip on the main timeline from an external class
(turn the MC invisible). My MC is named "mainframe"
my external class is this:
package {
public class MyClass{
public function MyClass() {
mainframe.visible=false
}
}
}
and in my fla I call it like this:
var myClass:MyClass = new MyClass();
This is the error I get:
1120: Access of undefined property mainframe.
Can someone please explain to me how to reference a movieClip on the main
timeline? I've spent 2 days looking for the answer and it's getting very
frustrating.
Thanks,
Brock
View Replies !
View Related
Accessing An Object Within A Class
hello all,
im kinda new to AS2.0 Classes, and im having some trouble
accessing objects within a MC's Class.
I have a MC on the timeline that has a class linked to it [the class extends MovieClip] I need the linked class to access objects within the MC, for example a text box and a few other graphics and MC's.
The class's script is : [where nav_text is a textbox located within the MC]
Code:
class NavigationDraw extends MovieClip
{
function NavigationDraw()
{
this.nav_text.autoSize = true
trace(this.nav_text._width)
}
}
How to I reference the objects? I would have throught it would be this, just as though you were referencing the text box in a frame of the MC's timeline.......
any ideas?
Thanks in Advance
View Replies !
View Related
Accessing Stage From The Class
I got the following file Tiles.as
Code:
package{
import flash.display.*;
public class Tiles extends MovieClip{
public var map:MovieClip = new MovieClip();
private var stageSet:Stage;
public function Tiles(stageRef:Stage):void{
stageSet = stageRef;
}
/* i draw on map MC with drawing API and i want it to be shown on Stage (main frame), but i cant access it*/
public function createMap():void{
map.graphics.lineStyle(1,0x990000);
map.graphics.moveTo(0,0);
map.graphics.lineTo(100,100);
stageSet.addChild(map);
}
}
}
and following code in Tiles.fla
Code:
var Tile:Tiles = new Tiles(Stage);
Tile.createMap();
and i get error like this :1067: Implicit coercion of a value of type Class to an unrelated type flash.display:Stage.
View Replies !
View Related
Accessing MC On Stage From Different Class In AS3
I'm new to AS3. I am a mediocre AS2 programmer, but I've taken some java courses so I guess I'm not too clueless that I can't eventually make the jump to AS3 : ) I have a new project that I am converting to AS3 from AS2 and am getting an error and am not sure what to do.
Background:
I need to create a scaled down version of Deal Or No Deal (with some major variations to the rules). I have a fla with a bunch of briefcase movieclips onstage named case1_mc, case2_mc, etc. There are 26 of them. I have a bunch of classes named Main.as (which is the document class for the fla), Briefcase.as, Game.as, Banker.as, etc.
My trouble is that within each briefcase mc there is a dynamic text field. I need to assign text to the dynamic text fields in each of the briefcase mc's. Here is my code from the Main class that is the document class that is causing the problem. This function is called from the Main constructor, to initialize the briefcase objects (not the visual ones, but the ones that will hold data to be displayed in the visual ones as needed):
Code:
function generateCases(_totalNumCases) {
for (var i=1; i<=_totalNumCases; i++) {
//generate the Briefcase objects
this["case"+i] = new Briefcase(i);
//assign the Briefcase object's caseNum to the displayed briefcase movieclip
this["case"+i+"_mc"].num_txt.text = this["case"+i].getCaseNum();
}
//randomize the caseValues_arr and assign values to Briefcases
shuffledCaseValues_arr = dollarValues_arr.shuffle();
//assign the shuffledCaseValues_arr values to the correlating Briefcases
//NOT WORKING
var incrementArray:Number = 0;
for (i=1; i <=_totalNumCases; i++) {
this["case" + i].setCaseValue(shuffledCaseValues_arr[incrementArray]);
incrementArray++;
}
}
When I compile and run in Flash CS3 I get the following output error (I get no compile errors anymore after much editing!):
ReferenceError: Error #1056: Cannot create property case1 on com.vertexinc.dealornodeal.Main.
at com.vertexinc.dealornodeal::Main/com.vertexinc.dealornodeal::generateCases()
at com.vertexinc.dealornodeal::Main$iinit()
So it appears that it just cannot run the function because it can't set the text properties of the briefcases? Any help is greatly appreciated! I had this working in AS2/Flash 8 but want to stick it out and get it going in AS3 as my first AS3 project!
View Replies !
View Related
Accessing Class Objects Via The Name
Hello
I have a class name Contents I am creating 5 objects of this class. Is there a way to keep track of the instance names assigned to the objects. What I am doing is get all the objects of Contents class and make button out of these and when user clicks a button the I want to reterieve descrioption from Contents class but I dont have any mean of storing the instance name. I think I am not making any sense so here is some code
Code:
public class TestContent extends EventDispatcher
{
//Class properties
private var _desc:String;
private static var _children:Array = new Array();
// Class Constructor
public function TestContent(name:String, desc:String)
{
// I want to store the name assigned to this object so I can use this later
this.instanceName = name;
_desc = desc;
TestContent._children.push(this);
}
public function get name():String
{
return this.instanceName;
}
public function get desc():String
{
return _desc;
}
public static function getChildren():Array
{
return _children;
}
So in another class I am using the number of objects of this class to create buttons
Code:
//Some other class
parentSprite:Sprite = new Sprite;
var mArray:Array = new Array;
mArray = TestContents.getChildren();
for (i = 0; i<mArray.length; i++)
{
var mc:MovieClip = new MovieClip(mArray[i])
parentSprite.addChild(mc);
}
parentSprite.addEventListener(MouseEvent.CLICK, onClikc);
public function onClick(e:MouseEvent):void
{
// here I wanna use the instance name of the TestContents object to call the desc property
trace(e.target.desc);
}
I hope I am making sense here
Thanks in advance
View Replies !
View Related
Accessing Instances From A Class
Hey guys!
Never really worked with class files like this before, and come to think of it, I donīt even know if itīs possible! Or how itīs possible anyways.
Iīve always used this.addEventListener and so on.
My question is, how do you access movieclips with instance names that is on the timeline in tha .fla you are importing the classfile into?
Is there a way to go, so you could write button_mc.addEventListener inside your .as file and have it access the function you defined in your .as file while the button_mc is inside the .fla?
Thanks in advance
/rundevo
View Replies !
View Related
Accessing An Object Within A Class
hello all,
im kinda new to AS2.0 Classes, and im having some trouble
accessing objects within a MC's Class.
I have a MC on the timeline that has a class linked to it [the class extends MovieClip] I need the linked class to access objects within the MC, for example a text box and a few other graphics and MC's.
The class's script is : [where nav_text is a textbox located within the MC]
Code:
class NavigationDraw extends MovieClip
{
function NavigationDraw()
{
this.nav_text.autoSize = true
trace(this.nav_text._width)
}
}
How to I reference the objects? I would have throught it would be this, just as though you were referencing the text box in a frame of the MC's timeline.......
any ideas?
Thanks in Advance
View Replies !
View Related
Accessing An Instance From With A Class...how?
I'm new to actoinscript 2, and I can't work this bit out...
I've got a movieclip in the library linked to the class Blob, that movieclip contains an instance named somethingMC... how do I access it thorugh the Blob class?
Code:
class Blob extends MoveClip
{
function Blob()
{
this.somethingMC.onRollOver = function() {trace("hello");}
}
}
This fails, apparantly there's no such property "somethingMC" but it is an instance within the movieClip.
Is there something obvious I'm doing wrong?
View Replies !
View Related
[F8] Accessing Variables In Custom Class
Yep... probably another scoping problem... but I can't figure it out.
I have a very simple script. I'm trying to pass a variable to a function and it's not working. Here is the code that exists inside the custom class:
Code:
public var myNumber:Number = 0;
public function testingVars(){
myNumber = 258;
trace(myNumber); // this works... returns 258.
myButton.onPress = function(){
trace(myNumber); // this returns "undefined".
}}
Like... why?!
View Replies !
View Related
Accessing Every Instance Of Custom Class At Once
hello
say i have a custom class that creates a box (using drawing API).
and i want to order these boxes in a grid
each box knows what they're co-ordinates are in this grid
is there a way i can tell every instance of this custom class to move from wherever they are to their respective grid co-ord with a single command ??
as in via a function in the class that says where each individual plugin goes accordingly to their co-ords....
thnx
View Replies !
View Related
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
View Replies !
View Related
Accessing Variables From One Class In Another - Not Working...
Class A instantiates classes B and C. All these classes are different. Both instances of B and C know who there parent is, so can therefore access each others varaibles through the first class.
Class B has the following variable:
Code:
private var aItemArray_array:Array;
This array is populated later on in the class.
I want to access the aItemArray_array from within class C.
I tried the following:
Code:
trace(_root.instanceOf_A.instanceOf_B.aItemArray_array)
It returns as undefined.
I tried to make the variable public, that resulted in the same trace. I also set the function in class B which sets the variable to public. That didn't work either...
What am I doing wrong here?
View Replies !
View Related
Accessing Parent Level From A Class
Hi, I'm writting a keyboard-control class to send input data to other movieclip-like classes at its same level. Currenlty my keyboard class have a function to process input data similar to this one:
Code:
private function onKeyDown():Void {
if (Key.getCode() == Key.UP) {
_parent[myMCLikeClassIntanceName].moveUp();
}
And I create it as usual at my application:
Code:
var myControl:Control = new Control();
However it seems not possible to this "Control" class to access the movieclip one. The "_parent" inside the "onKeyDown" does not return any path, just undefined. How could I access the movieclip at the same level of this Control class withought "going back" to the _root of my app?
View Replies !
View Related
Accessing An Instance On Stage From Within Another Class
Hi,
This really should be simple, but is proving frustratingly difficult! All I want to do is access one instance of a MovieClip on the stage (blue_mc) from within the class file of another MovieClip (red_mc).
e.g. One instance of "Blue" on the stage called "blue_mc", and one instance of "Red" on the stage called "red_mc". Both symbols are linked to class files (Blue.as and Red.as).
In Red.as, I set up a function to listen for a mouse down event. When this is triggered, I want to move the instance blue_mc. At the moment, though, I can't seem to get a reference to blue_mc.
I've looked into the new stage and root properties, but even though blue_mc is on the stage, it cannot be accessed using stage.getChildByName( "blue_mc" ) either.
Code for Red.as:
Code:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
public class Red extends MovieClip {
private function ballPressed( eventObject:Event ) {
trace( this.name + " pressed" );
trace( stage.getChildByName( 'blue_mc' ) + " not pressed" );
};
public function Red() {
trace( "Red loaded" );
this.addEventListener( MouseEvent.MOUSE_DOWN, ballPressed );
}
}
}
Can anyone point me in the right direction!?!
Thanks!!!
Chris
--
www.chrisblunt.com
View Replies !
View Related
Accessing XML-Data Loaded In A Class
Hi Guys,
I got a little problem with my classes. The structure is very simple: I've got a xml-file I want to load, wich is working fine. When loaded I'd like to access the xml-data from within my fla or within another class. That's the point where I'm stuck right now. I can access the xml-data from within the class, but not from another class. I hope someone can help me.
Here's my xml-class [xmldata.as]:
PHP Code:
package
{
import flash.net.URLLoader
import flash.net.URLRequest
import flash.xml.XMLDocument;
import flash.errors.*
import flash.events.*
public class xmldata extends EventDispatcher {
private var xmlloader : URLLoader;
public static var mainXML : XML;
// public static var getit:XML;
public function xmldata(datafile) {
xmlloader = new URLLoader();
xmlloader.addEventListener(Event.COMPLETE, onComplete);
xmlloader.load(new URLRequest(datafile));
}
private function onComplete(e:Event) {
try {
mainXML = new XML(xmlloader.data)
trace(mainXML.hotspots.hotspot.length());
dispatchEvent(new Event("xmlloaded"));
}
catch(er:Error) {
trace("Error: " + er.message)
return;
}
}
}
}
Just for testing I put the following code into a .fla which is ment to be in a class further on:
PHP Code:
import xmldata;
var test:xmldata = new xmldata("vars.xml");
test.addEventListener("xmlloaded",soldier)
function soldier(e:Event){
trace(xmldata);
}
Any ideas or suggestions? I'd be glad to have a notice!
Greets
hellslawyer
[EDIT]: To get it clear I uploaded a simple example of what I want to make.
View Replies !
View Related
Multi-class Accessing Question
hi,
i'm new to OOP in as3 and was wondering how I could have an array that functions as if it was a preset holder per say. I guess what I mean is...in my main class, how can I set one array to govern different variables contained in all my potential sub classes. i hope that makes sense. if any of you guys could help me out -- i'm not asking for specific code examples, just a basic explanation of how this might be achieved using some as3 syntax and such -- i'd really appreciate it.
thanks!
View Replies !
View Related
Accessing An Object On The Stage From Within A Class?
It's me again
Naah, this is a simple one. I think. If I've created a label on the stage just by sticking the code below on the first frame of the .fla:
Code:
var imgLabel:Label = new Label();
imgLabel.text = "Hello World";
imgLabel.x = 100;
imgLabel.y = 100;
stage.addChild(imgLabel);
and right below that I'm creating an instance of an image-scrolly class (that extends MovieClip) with:
Code:
var mySlideShow = new FeaturedPanel("slideshow_name");
stage.addChild(mySlideShow);
... then how the heck do you get at the label, from the image scroller thing?
I've got a function in the FeaturedPanel class that's fired when you click an image within it, with just "imgLabel.text = imgCaption;" - and it keeps telling me "Access of undefined property imgLabel."
Nuh?
View Replies !
View Related
Accessing Loader Content Outside A Class
Hi there,
i wonder how to access Variables which are loaded in class from fla...
I maintain some script to load variables via URLLoader into array in class, put event listener into class...
everething work properly inside the class
My question is how to access the array outside the class when the variables are loaded. some dispatcher, or?
thx
View Replies !
View Related
Accessing Stage Variables From Class
hi ..
I have written some action script (well most of the script) on main time line without using any CLASS - (bad practice) .. there are many variables that i have created there and the stage objects .. I am using those objects on main time line as ..
ActionScript Code:
this.mVideo.someProperty ...
now i have written a class say .. "Test.as" which i have placed in the same directory. now while being in that class method, how can i access variables define on the timeline actionscript + on the stage ..
how can i access that "mVideo" object from that class ??
View Replies !
View Related
Accessing Movieclip At Root From Class ?
I cannot access any movieclip(or anything else) on the stage/root from inside class codes :
ActionScript Code:
package mypack {
import flash.display.MovieClip;
public class MyClass extends MovieClip {
public function MyClass () {
trace(root.myMC); // COMPILE ERROR = 1119: Access of possibly undefined property myMC through a reference with static type flash.display:DisplayObject.
}
}
}
Why is that ?
View Replies !
View Related
Accessing Properties Of A Class's Parent
I am beginning to understand AS3. With my current project I am avoiding use of timelines, and trying to be as OOP as I can using separate .as files for all of my classes. The big picture is slowly coming to me, but there is still much that I don't really understand.
One thing that I understand now (and correct me if I am wrong) is that a class cannot access the properties of it's parent within the constructor function because it does not yet understand that it has a parent (am I on the right track here?).
Since each instance of my child class absolutely must reference it's parent in order to set it's own property values, I have created a function below the constructor function whose sole purpose is to access the parent's properties to set it's own property values.
I know this is extremely vague, but here is an example of what I am getting at. I just need to know if I am doing things in the most CPU-efficient manner.
ActionScript Code:
package
{
import flash.display.*;
import flash.event.*;
public class MyChild extends Sprite
{
var a:Number;
var b:Number;
var c:Number;
public function MyChild()
{
this.addEventListener(Event:ADDED_TO_STAGE, initFunction);
}
function initFunction(event:Event):void
{
a = this.parent.A;
b = this.parent.B;
c = this.parent.C;
}
}
}
View Replies !
View Related
Help Accessing A MovieClip From Inside A Class
I have a Class that works fine. It references a MovieClip. I used the instance name from within the Class.
The problem is that I want to extend this class. When I extend the Class get the error:Access of Undefine Property _mc.
If I declare _mc, it resolves that error, but then the class doesn't recognize the MovieClips.
Help me out, what am I missing?
View Replies !
View Related
Loaded Swf Accessing Class Var In A Parent Swf
I have a template swf using a Template class. This is loaded into a parent swf which uses a Shell class. I'm trying to get Template class to access a variable with the Shell class. Is there a way to do it without importing the Shell class. template.fla keeps throwing compile errors, obviously because Shell doesn't exist yet. I'm still trying to grasp some OOP concepts, so help is appreciated.
Thanks,
View Replies !
View Related
|