View Full Version : How to access clip on stage from external Class
GraaB
02-13-2009, 07:06 PM
Hi guys, i have a little problem annoying me since a few hours....
I've got a textfield on the main Fla called 'debug'
i've created a Class which refers to the textfield, but when i launch my fla, it says:
1120: Access of undefined property debug.
package {
.....
private function write (e:MouseEvent):void
{
debug.text = "test";
}
}
Don't know what to do, i've tried a few things, but nothing works....
Help Please...
xxneon
02-13-2009, 08:00 PM
is your class being used as the document class? or is it another class where your creating instances of that class?
GraaB
02-13-2009, 08:31 PM
The class is not the main document,
i've created a document and put a textfield on stage, and i import my class from this flash document.
I think that the textfield is not Added_to_stage when importing the class, so it doesn't see it.... and i don't know how to do it... :confused:
xxneon
02-14-2009, 01:01 AM
can you zip up your files and post them here.
GraaB
02-14-2009, 05:32 AM
Okay, you can get the zip here:
http://www.endeka.fr/up/
the file is SS3.zip
Arif-sama
02-14-2009, 05:42 AM
package {
.....
private function write (e:MouseEvent):void
{
debug.text = "test";
}
}
im not sure about it, but try it this way:
package {
.....
private function write (e:MouseEvent):void
{
this.text = "test";
}
}
GraaB
02-16-2009, 07:44 AM
I've been trying for hours ,different ways to pass thru that problem, but i'm not able to do it...
So i try to pass a String var from my class to the main .fla, but it doesn't works anyway !!!
Here what's in my main .fla:
import classes.joueurs.*;
var detecteur:String;
this.addEventListener(Event.ENTER_FRAME, verif);
function verif (e:Event):void {
trace(detecteur);
}
Here is my class:
package classes.joueurs
{
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.text.TextField;
import flash.events.MouseEvent;
public class Defenseur extends Sprite
{
private var detecteur:String;
public function Defenseur()
{
var def:joueur = new joueur();
this.addChild(def);
def.addEventListener(MouseEvent.CLICK, detecte);
}
private function detecte(e:MouseEvent):void
{
parent.detecteur=this.toString;
}
}
}
And i always get thet 1119: Access error of detecteur !!!
What's wrong with AS3 !!!
you can access any object from a class by setting them instead since it's only for debug why not creating a TextField variable in your joueur class:
public var debug_text:TextField = null;
then in the main fla where the debug textfield is after you create your joueur instance just set it's textfield like this:
def.debug_text = debug;
now you can access the debug textfield from your class:
public function access_external_debug():void{
if(debug_text != null){
//code here
}
}
GraaB
02-16-2009, 06:26 PM
Thanks for your answer ;), but what i am trying to do with my variable on stage, is to detect when a clip is selected. It's easier to change a global variable on stage that every duplicated MovieClip on scene could access.
I could do the same with a for{} loop checking every "_detect" var on each duplicated movieClip, but i don't really like that way to do it.
If there's no other way, i'll do it like that, but i'd rather access a unique global variable.
If you have any solution for checking "focused" movieclips on stage, tell me !!!
;)
Thanks for your answer ;), but what i am trying to do with my variable on stage, is to detect when a clip is selected. It's easier to change a global variable on stage that every duplicated MovieClip on scene could access.
I could do the same with a for{} loop checking every "_detect" var on each duplicated movieClip, but i don't really like that way to do it.
If there's no other way, i'll do it like that, but i'd rather access a unique global variable.
If you have any solution for checking "focused" movieclips on stage, tell me !!!
;)
Most of your thread was about accessing a texfield on a stage from a class so that's what I tried to answer for you.
GraaB
02-17-2009, 06:39 AM
Yes, and your answer was quite a good solution !!!, but i was looking for some way to access my stage from my class, and with that TextField i was sending a variable to the stage...
I've seen in various Forums over there, that the Stage to class access is a problem for most AS3 developpers....
Anyway i'm thinking about using your solution to solve my problem, but i don't really like the for{} Loop to check all Mc's on stage...
well I don't really understand what you are trying to do but in your case you can use the Event.ADDED_TO_STAGE in your class to access the stage property from inside your class. Obviously this event will trigger once you add to the display list your instance of your joueur class (addChild(joueur instance)) not when you create an instance. Remember also that a class can have a kinda "global" variable by declaring a variable with the keyword "static".
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.