-
[RESOLVED] manage code via package
Hi,
I am new and need some help.
My code structure is
FlashTesting --> folder contains
Test.fla with one button called cmd_button
engine --> folder contains
Main.as file
code --> folder contains
Test.as file which has code to add EventListener to cmd_button
cmd_button.addEventListener(MouseEvent.CLICK, cmd_button_click);
When I compile output says
1120: Access of undefined property cmd_button
-------------------------------------------------------------
folder structure
FlashTesting -->engine--->code
-------------------------------------------------------------
All I want to access cmd_button to add EventListener which is in code folder.
Seems can't access fla components.
Thanks
-
Does the button sit on stage with an instance name or are you creating it somewhere before adding the listener?
-
5+5=55
Make sure you have the filename the same as the class name. Main.as should be "public class Main" and Test.as should be "public class Test".
The package must correspond to the folder it's in. For Test.as, this should be
"package engine.code"
Also, do you have your Document Class set to Main?
These might help a bit too:
http://www.8bitrocket.com/newsdispla...?newspage=7754
http://tutorials.lastashero.com/2006..._packages.html
-
Originally Posted by Schfifty Five
Make sure you have the filename the same as the class name. Main.as should be "public class Main" and Test.as should be "public class Test".
The package must correspond to the folder it's in. For Test.as, this should be
"package engine.code"
Also, do you have your Document Class set to Main?
I tried onething and than message go away.
I extended Main from Test like
public class Test extends Main
My document Class is set to Main. So is it necessary to extend Main class from other classes if I want to access button in fla or anything?
Button is already created in fla and have instance name.
Thanks
-
Please help me with this.
Can I use button like this added in NewClass?
Giving error:1120: Access of undefined property cmd_connect.
Document class is Main and is defined in fla. Button is in the fla 1 frame and name is cmd_connect.
Main file is with fla file and NewClass.as is engine folder.
ALL I WANT is to use cmd_button in NewClass. Someone improve it and show me please.
package
{
import engine.NewClass;
import flash.display.MovieClip;
import flash.events.*;
public class Main extends MovieClip
{
public function Main()
{
var sfs:NewClass = new NewClass();
trace("In");
}
}
}
--------------------------------------------------------
package engine
{
import flash.display.MovieClip;
import flash.events.*;
public class NewClass
{
public function NewClass()
{
init();
}
private function init():void
{
cmd_connect.addEventListener(MouseEvent.CLICK, cmd_connect_click);
}
private function cmd_connect_click(evt:Event):void
{
trace("Hello");
}
}
}
-
5+5=55
-
5+5=55
I think you need to give a reference to Main in NewClass.
Something like:
PHP Code:
package
{
import engine.NewClass;
import flash.display.MovieClip;
import flash.events.*;
public class Main extends MovieClip
{
public function Main()
{
var sfs:NewClass = new NewClass(this);
trace("In");
}
}
}
PHP Code:
package engine
{
import flash.display.MovieClip;
import flash.events.*;
import Main;
public class NewClass
{
private var mainRef:Main;
public function NewClass(mainRef:Main)
{
this.mainRef = mainRef;
init();
}
private function init():void
{
mainRef.cmd_connect.addEventListener(MouseEvent.CLICK, cmd_connect_click);
}
private function cmd_connect_click(evt:Event):void
{
trace("Hello");
}
}
}
-
Thanks alot. Really appreciate your help.
This is solved. Hope to disturb you again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|