Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to code different scenes in package function

Participant ,
Oct 13, 2013 Oct 13, 2013

package actions {

    

    import flash.events.MouseEvent;

    import flash.display.MovieClip;

    import flash.text.TextField;

   

   

    import flash.events.Event;

    import flash.text.*;

    import flash.net.*;

   

    

        

    public class submit extends MovieClip {

        

        public function submit():void {


     }

}

Somehow it comes to a point I need to learn how to use package vs previously I put all the codes into .fla..

So I'm learning this, this is the basic package, when in the main.fla I have document Class linked to 'action.submit'. And I have a folder called 'action' and inside is this 'submit.as' that has the code above in it.

To my understand whatever within 

public function submit():void {

    

     }

will  be loaded first? But my question is what happend if I have more than 1 scene, like for example scene 1 I have 'bttn1', scene 2 I have 'bttn2'. If I do it like this

public class submit extends MovieClip {

        

        public function submit():void {

              

              bttn1.buttonMode = true;

               bttn1.addEventListener(MouseEvent.MOUSE_DOWN, gotoScene2);

               bttn2.buttonMode = true;

               bttn2.addEventListener(MouseEvent.MOUSE_DOWN, checkLogin);

     }

}

will both buttons executed when user press them?

Second question is if I want on scene 2, to run a function whenever scene 2 is loaded, how do I do that in package?

Thank you

TOPICS
ActionScript
2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Oct 14, 2013 Oct 14, 2013

You can have functions that run when only certain objects are on stage (which is equivalent to what you're asking). However, that requires advanced concepts you're probably not ready for.

You might want to consider instead having a MovieClip in scene 1 that has the functionality that you need to have happen in scene 1 and another MC that has different functionality, but the same method name, in scene 2.

So:

public interface IDoer {

     function doSomething():void;

}

public class Scene1Doer extends Mo

...
Translate
Community Expert ,
Oct 13, 2013 Oct 13, 2013

you shouldn't those buttons to the main timeline.  add them to a movieclip and create a class for that movieclip.  add the code for your buttons to that movieclip's class.  add that movieclip to your main timeline etc.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 13, 2013 Oct 13, 2013

Ok, I get what you mean, load externally the buttons into main timeline and apply class for them on their own.

Thats good I can do that, but what about on main timeline I have multiple scenes, and for example I want on scene 2 once the scene is loaded, I want to load an mc into  'scene2mc', etc. Can I do that in the package? Or I'll have do it the old way have actionscript on scene2?

Is my question confusing I hope not? So basically in here

public class submit extends MovieClip {

        

        public function submit():void {


     }

}

There's no way I can make function that only runs on scene 2 but not scene 1? I hope I made it understanding

Thank you for reply

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 14, 2013 Oct 14, 2013

Sorry, let me rephrase the question...

on Scene 2 right when it starts, it should grabs 'fname' ( first name ) from mysql. and display it on the screen.

I have an input box on Scene 2 - 'fname2'

In my package I have this function

public function processCreate(showCondition):void {

            var urlVars:URLVariables = new URLVariables();

            

            var urlFileRequest:URLRequest = new URLRequest("php/controlpanel.php");

            

            urlFileRequest.method = URLRequestMethod.POST;

                        

            urlFileRequest.data = urlVars;

           

            var php2Loader:URLLoader = new URLLoader();

            php2Loader.dataFormat = URLLoaderDataFormat.VARIABLES;

            if (showCondition=="createprofile"){

                php2Loader.addEventListener(Event.COMPLETE, showResult); }

            if (showCondition=="retrieveData"){

                php2Loader.addEventListener(Event.COMPLETE, showResultS2); }

           

            urlVars.systemCall = showCondition;

            urlVars.email = email.text;

            urlVars.password = password.text;

            urlVars.fname = fname.text;

            urlVars.lname = lname.text;

           

            php2Loader.load(urlFileRequest);

           

           

       

        }

back to Scene 2, I have in AS

stop();

processCreate("retrieveData");  // so that it will run the function when scene2 is loaded.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 14, 2013 Oct 14, 2013

public function showResultS2(event:Event):void {

fname2.autoSize = TextFieldAutoSize.LEFT;

fname2.text = "" + event.target.data.systemResult;  // systemResult should return text from fname field

}

So the input box fname2 suppose to show the fname field right from the beginning but it doesn't?

This is part of the php file:

else if ($_POST['systemCall'] == "retrieveData") {

            $selsql = "SELECT * FROM users WHERE email='$email'";

            $selquery = mysql_query($selsql);

           

            $login_counter2 = mysql_num_rows($selquery);

   

            if ($login_counter2 > 0) {

                while ($data = mysql_fetch_array($query)) {                   

                    $fname1 = $data["fname"];

                    print "systemResult=$fname1";

                }

            }

    }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 14, 2013 Oct 14, 2013

I think the problem may be on flash scene 2, I have only this?

stop();

processCreate("retrieveData");

May be I need an onload complete event to call this function, would that better?

Thank you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 14, 2013 Oct 14, 2013

There is no reason the OP can't put those buttons on the stage. The trick is to uncheck "declare stage instances automatically" in the publish settings, then define the variables in the AS file so code hinting will work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 14, 2013 Oct 14, 2013

You can have functions that run when only certain objects are on stage (which is equivalent to what you're asking). However, that requires advanced concepts you're probably not ready for.

You might want to consider instead having a MovieClip in scene 1 that has the functionality that you need to have happen in scene 1 and another MC that has different functionality, but the same method name, in scene 2.

So:

public interface IDoer {

     function doSomething():void;

}

public class Scene1Doer extends MovieClip implements IDoer {

     public function doSomething():void {

          //do whatever you need to do in scene 1

     }

}

public class Scene2Doer extends MovieClip implements IDoer {

     public function doSomething():void {

          //do whatever you need to do in scene 2

     }

}

Then, on your timeline, you would place both instances of library symbols that have Scene1Doer and Scene2Doer as their base Classes. Call both instances doerMovieClip.

Your main Document would look something like this:

public class MainDocument extends MovieClip {

     public var btn1:SimpleButton;

     public var btn2:SimpleButton;

     protected var _doerMovieClip:IDoer;

     public function MainDocument() {

          super();

          btn1.addEventListener(MouseEvent.CLICK, goToScene2);

          btn2.addEventListener(MouseEvent.CLICK, doSomething);

     }

     public function get doerMovieClip():IDoer{

          return _doerMovieClip;

     }

     public function set doerMovieClip(value:IDoer):void {
           _doerMovieClip = value;   
      }    
      //skipping goToScene2, not dealing with the issues involved in that in this post    
      protected function doSomething(e:MouseEvent):void {
           if (_doerMovieClip) {
               _doerMovieClip.doSomething();
           }
      }
}

Note that you may get warnings that your implementations of doerMovieClip are not the same. Chalk it up to the Flash team not expecting people to actually program to interfaces on the timeline and move on.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 14, 2013 Oct 14, 2013

hmmm

so I put a btn2 on scene2? and have user click on btn2 to activate doSomething?

Is it possible to do something like on scene1 when user click btn1, it will execute both gotoScene2 and doSomething, and then on scene2 the result of doSomething ( lets say doSomething will collect fname data from my database) will automatically appear in a input box?

If on scene1 btn1 executed doSomething, will the returned value still accessible on scene2, I think this is what my real confusion is, if I access to my database thru php on scene1, will the data still be usable on scene2?

Thanks a lot.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 14, 2013 Oct 14, 2013

No, the code you posted implied that both buttons "live" for the entire life of the swf. If they don't, just put each button in the MovieClip that you're using in each scene.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 14, 2013 Oct 14, 2013


"The trick is to uncheck "declare stage instances automatically" in the publish settings"

after I did this, it ignores the stop() and keep looping scene1 to scene2 nonstop?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 14, 2013 Oct 14, 2013

I have stop() on frame 1 on both scene 1, 2

when I uncheck "declare stage instances... " , it just goes from scene to another scene nonstop.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 15, 2013 Oct 15, 2013

you know.. I just realized how much extra troubles to do this in the Class way when you can spend less than 1 min put an CLICK event in scene 2 to make buttons work..

Thank you all for  helping me.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 15, 2013 Oct 15, 2013

Yes, using Classes does require that you pay attention to detail and have at least some understanding of programming. If all you're ever building is little banner ads and that's all you ever want to do, you should probably just stick with what you can handle.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 15, 2013 Oct 15, 2013

yes, you're absolutely right, I'm going through all the document class basics now I got the buttons working ( Export for  Actionscript under Properties ) with external as.

Problem now is that on Scene 2 I'm suppose to use the input box text  ( fname.text) to do something else but I got stuck fname.text from Scene 1 is not accessible in Scene 2..

I tried in the Main Class have this code

public var fnameNew = fname.text;

Still make no difference Scene 2 can't recognize fnameNew too.

Help and thank you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 15, 2013 Oct 15, 2013

Create a public property on the Class you're using in scene 2 with a getter/setter pair like I showed you in the post with sample Main document code. In the setter in Main document for that instance, add code that will set that value from the text that it got from scene 1. Make sure that you're waiting to get the text until after the user has populated the field.

If you haven't gotten to correct code by my lunchtime here, I'll see if I can find time to write up some example code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 16, 2013 Oct 16, 2013
LATEST

Spent the whole day.. no luck with pair functions I just couldn't get it..  it just give me blinking with scenes

But then just happens someone already asked similar question in this forum and I took their solution,

I think that was Ned's answer he simply say never work with scenes on flash thats as2 thing belong to the past where it should be

so I just deleted all the scenes and put on timeline, but different layers so one 'scene' cover up the other below it.

now all of the scenes line up on the same frame and there no trouble reading anything

thanks a lot for offer doing the code, it's very kind of you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 15, 2013 Oct 15, 2013

That sounds like you have an error in your Actionscript (probably you didn't declare the variables in the file, which was advice I also gave you). Did you have strict mode and warnings on? If so, you should have seen the errors in the errors panel.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines