A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [RESOLVED] manage code via package

  1. #1
    Member
    Join Date
    May 2006
    Posts
    55

    resolved [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

  2. #2
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Does the button sit on stage with an instance name or are you creating it somewhere before adding the listener?

  3. #3
    5+5=55 Schfifty Five's Avatar
    Join Date
    Jun 2006
    Posts
    698
    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

  4. #4
    Member
    Join Date
    May 2006
    Posts
    55
    Quote Originally Posted by Schfifty Five View Post
    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

  5. #5
    Member
    Join Date
    May 2006
    Posts
    55
    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");
    }
    }
    }

  6. #6
    5+5=55 Schfifty Five's Avatar
    Join Date
    Jun 2006
    Posts
    698
    *Double post, sorry*

  7. #7
    5+5=55 Schfifty Five's Avatar
    Join Date
    Jun 2006
    Posts
    698
    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.CLICKcmd_connect_click);
    }

    private function 
    cmd_connect_click(evt:Event):void
    {
    trace("Hello");
    }
    }


  8. #8
    Member
    Join Date
    May 2006
    Posts
    55
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center