A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: importing

  1. #1
    Member
    Join Date
    Sep 2007
    Posts
    60

    importing

    Hello,

    i have drawn buttons on my stage. They all set to export for as3.
    i then made a class for buttons


    package
    {
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.system.fscommand;

    public class Buttons extends MovieClip
    {
    public function Buttons()
    {
    newgame_btn.addEventListener(MouseEvent.CLICK, onClick);
    continue_btn.addEventListener(MouseEvent.CLICK, onClick1);
    options_btn.addEventListener(MouseEvent.CLICK, onClick2);
    credits_btn.addEventListener(MouseEvent.CLICK, onClick3);
    exit_btn.addEventListener(MouseEvent.CLICK, onClick4);
    }

    public function onClick(event:MouseEvent):void
    {
    gotoAndStop(4);
    }

    public function onClick1(event:MouseEvent):void
    {
    trace("continue the game!!");
    }

    public function onClick2(event:MouseEvent):void
    {
    gotoAndStop(3);
    }

    public function onClick3(event:MouseEvent):void
    {
    gotoAndStop(2);
    }

    public function onClick4(event:MouseEvent):void
    {
    fscommand("quit");
    }
    }
    }
    AND

    then i put in my document class ; import Buttons;

    nothing happens and no errors...

    what is wrong with what i did??

  2. #2
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    well you didn't add any buttons to the display list also for the document class you specify the name of the package Buttons.

    PHP Code:
    package
    {
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.system.fscommand;

    public class 
    Buttons extends MovieClip
    {

    public function 
    Buttons()
    {
    var 
    newgame_btn:Button = new Button;
    var 
    continue_btn:Button  = new Button;
    var 
    options_btn:Button = new Button;
    var 
    credits_btn:Button = new Button;
    var 
    exit_btn:Button = new Button;

    newgame_btn.width 100;
    newgame_btn.height 22.5
    newgame_btn.=0;
    newgame_btn.=50;

    continue_btn.width 100;
    continue_btn.height 22.5
    continue_btn.=110;
    continue_btn.=50;

    options_btn.width 100;
    options_btn.height 22.5
    options_btn.=210;
    options_btn.=50;

    credits_btn.width 100;
    credits_btn.height 22.5
    credits_btn.=310;
    credits_btn.=50;

    exit_btn.width 100;
    exit_btn.height 22.5
    exit_btn.=410;
    exit_btn.=50;

    addChild(newgame_btn);
    addChild(continue_btn);
    addChild(options_btn);
    addChild(credits_btn);
    addChild(exit_btn);

    newgame_btn.addEventListener(MouseEvent.CLICKonClick);
    continue_btn.addEventListener(MouseEvent.CLICKonClick1);
    options_btn.addEventListener(MouseEvent.CLICKonClick2);
    credits_btn.addEventListener(MouseEvent.CLICKonClick3);
    exit_btn.addEventListener(MouseEvent.CLICKonClick4);
    }

    public function 
    onClick(event:MouseEvent):void
    {
    gotoAndStop(4);
    }

    public function 
    onClick1(event:MouseEvent):void
    {
    trace("continue the game!!");
    }

    public function 
    onClick2(event:MouseEvent):void
    {
    gotoAndStop(3);
    }

    public function 
    onClick3(event:MouseEvent):void
    {
    gotoAndStop(2);
    }

    public function 
    onClick4(event:MouseEvent):void
    {
    fscommand("quit");
    }
    }

    ~calmchess~

  3. #3
    Member
    Join Date
    Sep 2007
    Posts
    60
    sorry but what do you mean by

    you specify the name of the package Buttons

    this is my doc class

    package
    {
    import flash.display.MovieClip;
    import Buttons;

    public class BamBam extends MovieClip
    {
    public function BamBam()
    {

    }
    }
    }
    /*** also note that the buttons are placed on stage already ... do i still need to addchild?????
    Last edited by nuchri; 06-13-2009 at 11:03 PM.

  4. #4
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    oh i misunderstood the begining post.........to import your Buttons class try.
    PHP Code:
    package
    {
    import flash.display.MovieClip;
    import Buttons;

    public class 
    BamBam extends MovieClip
    {

    public function 
    BamBam()
    {
    var 
    btnClass:Buttons = new Buttons();
    addChild(btnClass);
    }
    }

    ~calmchess~

  5. #5
    Member
    Join Date
    Sep 2007
    Posts
    60
    i copied your first code of class buttons and then placed the other code in my doc lass.


    **i want to mention my buttons are on the stage already placed... all i want is my button class to talk to them via the doc class

    but i get all sort of errors when running the code as is...

    1046: Type was not found or was not a compile-time constant: Button.
    1046: Type was not found or was not a compile-time constant: Button.
    1046: Type was not found or was not a compile-time constant: Button.
    1046: Type was not found or was not a compile-time constant: Button.
    1046: Type was not found or was not a compile-time constant: Button.
    1180: Call to a possibly undefined method Button.
    1180: Call to a possibly undefined method Button.
    1180: Call to a possibly undefined method Button.
    1180: Call to a possibly undefined method Button.
    1180: Call to a possibly undefined method Button.
    Warning: 1060: Migration issue: The method Button is no longer supported. The Button class has been renamed SimpleButton..
    Warning: 1060: Migration issue: The method Button is no longer supported. The Button class has been renamed SimpleButton..
    Warning: 1060: Migration issue: The method Button is no longer supported. The Button class has been renamed SimpleButton..
    Warning: 1060: Migration issue: The method Button is no longer supported. The Button class has been renamed SimpleButton..
    Warning: 1060: Migration issue: The method Button is no longer supported. The Button class has been renamed SimpleButton..

    each error 5 times ...i guess for the five buttons....

  6. #6
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    those errors are cause by an import issue....import.fl.controls.Button....if you want to use buttons that are on stage then you must pass their refrences as a parameter from the document class into the class with the button eventListners. I just create buttons with actionscript....so remove the buttons i created above and pass the stage buttons refrences in.
    ~calmchess~

  7. #7
    Member
    Join Date
    Sep 2007
    Posts
    60
    Hello,

    This is my doc class code now...

    package
    {
    import flash.display.MovieClip;
    import Buttons;

    public class BamBam extends MovieClip
    {
    public function BamBam()
    {
    var btnClass:Buttons = new Buttons();
    addChild(btnClass);
    }
    }
    }
    and this the buttons class

    package
    {
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.system.fscommand;
    import fl.controls.Button;

    public class Buttons extends MovieClip
    {

    public function Buttons()
    {
    newgame_btn.addEventListener(MouseEvent.CLICK, onClick);
    continue_btn.addEventListener(MouseEvent.CLICK, onClick1);
    options_btn.addEventListener(MouseEvent.CLICK, onClick2);
    credits_btn.addEventListener(MouseEvent.CLICK, onClick3);
    exit_btn.addEventListener(MouseEvent.CLICK, onClick4);
    }

    public function onClick(event:MouseEvent):void
    {
    gotoAndStop(4);
    }

    public function onClick1(event:MouseEvent):void
    {
    trace("continue the game!!");
    }

    public function onClick2(event:MouseEvent):void
    {
    gotoAndStop(3);
    }

    public function onClick3(event:MouseEvent):void
    {
    gotoAndStop(2);
    }

    public function onClick4(event:MouseEvent):void
    {
    fscommand("quit");
    }
    }
    }

    on my fla....
    example: the newgame_btn is on stage already... i changed its properties to export to actionscript... also i put in the instance name of newgame_btn
    (same is done for other 4 buttons...)


    i get this error...

    1046: Type was not found or was not a compile-time constant: exit_btn.
    1046: Type was not found or was not a compile-time constant: credits_btn.
    1046: Type was not found or was not a compile-time constant: options_btn.
    1046: Type was not found or was not a compile-time constant: continue_btn.
    1046: Type was not found or was not a compile-time constant: newgame_btn.

    there is a step i am sure i am messing up on.. but which??

    thank you

  8. #8
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    pass the buttons

    PHP Code:
    package
    {
    import flash.display.MovieClip;
    import Buttons;

    public class 
    BamBam extends MovieClip
    {
    public function 
    BamBam()
    {
    var 
    btnClass:Buttons = new Buttons(exit_btn,credits_btn,options_btn,continue_btn,newgame_btn);

    }



    PHP Code:
    package 

    import flash.display.MovieClip
    import flash.events.MouseEvent
    import flash.system.fscommand;
    import fl.controls.Button;

    public class 
    Buttons extends MovieClip 


    public function 
    Buttons(exit_btn,credits_btn,options_btn,continue_btn,newgame_btn

    newgame_btn.addEventListener(MouseEvent.CLICKonClick); 
    continue_btn.addEventListener(MouseEvent.CLICKonClick1); 
    options_btn.addEventListener(MouseEvent.CLICKonClick2); 
    credits_btn.addEventListener(MouseEvent.CLICKonClick3); 
    exit_btn.addEventListener(MouseEvent.CLICKonClick4); 


    public function 
    onClick(event:MouseEvent):void 

    gotoAndStop(4); 


    public function 
    onClick1(event:MouseEvent):void 

    trace("continue the game!!"); 


    public function 
    onClick2(event:MouseEvent):void 

    gotoAndStop(3); 


    public function 
    onClick3(event:MouseEvent):void 

    gotoAndStop(2); 


    public function 
    onClick4(event:MouseEvent):void 

    fscommand("quit"); 



    ~calmchess~

  9. #9
    Member
    Join Date
    Sep 2007
    Posts
    60
    Thank you so much it works but with a minor issue....

    for some reason newgame and options and credits wont go to their frames....exit and continues works as it should but the other three dont do what they are suppose to...


    this is the button class...

    package
    {
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.system.fscommand;

    public class Buttons extends MovieClip
    {

    public function Buttons(exit_btn,credits_btn,options_btn,continue_ btn,newgame_btn)
    {
    newgame_btn.addEventListener(MouseEvent.CLICK, onClick);
    continue_btn.addEventListener(MouseEvent.CLICK, onClick1);
    options_btn.addEventListener(MouseEvent.CLICK, onClick2);
    credits_btn.addEventListener(MouseEvent.CLICK, onClick3);
    exit_btn.addEventListener(MouseEvent.CLICK, onClick4);
    }

    public function onClick(event:MouseEvent):void
    {
    gotoAndPlay(4);
    }

    public function onClick1(event:MouseEvent):void
    {
    trace("continue the game!!");
    }

    public function onClick2(event:MouseEvent):void
    {
    gotoAndPlay(3);
    }

    public function onClick3(event:MouseEvent):void
    {
    gotoAndPlay(2);
    }

    public function onClick4(event:MouseEvent):void
    {
    fscommand("quit");
    }
    }
    }
    *** i created another layer with something in frame 4... which i suppose when press newgame button it will go there.....

  10. #10
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    Sombody else will have to help with this i can't find anything except how to change an MC's timeline such as
    PHP Code:
    mc0.gotoAndPlay(4
    ~calmchess~

  11. #11
    Member
    Join Date
    Sep 2007
    Posts
    60
    i will try to figure it out but i appreciate everything you did to help me.

  12. #12
    Member
    Join Date
    Sep 2007
    Posts
    60
    i figured the issue and resolved it...

    now for the next issue...

    i have a video and music playing in the background...

    when i try to remove the video for example i get this error

    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
    at flash.display:isplayObjectContainer/removeChild()
    at Buttons/onClick()


    **what is that because of...

    i want to press the newgame button and then it should remove at same time the video in background..

  13. #13
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    the video needs to be inside a display container such as a sprite then you say.......con.removeChild(vidCon);
    ~calmchess~

  14. #14
    Member
    Join Date
    Sep 2007
    Posts
    60
    The way i have it setup is...
    i have the main fla.. i have a document class...i have a video class... a sound class ... and finally a button class...

    question is ...

    in my button class under the newgame_btn...
    when pressed i want it to remove the video and sound in the background...

    when i put this code ....

    public function onclick(event:MouseEvent):void
    {
    ruut.gotoAndStop(4);
    var videoflv = new videoflv
    removeChild(v);
    v = null;
    }

    the swf loads with this error
    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
    at flash.display:isplayObjectContainer/removeChild()
    at Buttons/onClick()


    **so am i not importing something in my button class or something i have to do elsewhere or.....

  15. #15
    Member
    Join Date
    Sep 2007
    Posts
    60
    i figured how to remove the video... took many trial and error...

    now the issue is how to remove the audio that playing in background...

    i can possible stop it but it isnt same as removing it

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