A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: keyboard nav through multiple movieclips

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    10

    keyboard nav through multiple movieclips

    I'm hoping to add some functionality to the presentation template. Currently you can only move from one page to the next. So if I want an animation on a page, no problem I'll just add a stop script at the end. No big deal. But if I want Multiple animations (just trying to replace powerpoint here) then I get into trouble.

    Ideally this is what I would like:
    Each page is one frame on the main timeline. Hitting left/right goes to the next frame, unless the movieclip on that frame also has additional frames. Then it should move to the next frame within that, etc.

    I can't figure out that if statement though. I had another bit of script going on my first go, but ran into some issues so thought it best to create all of the scripting on the main timeline.
    Initially I created a boolean variable, then ran an if statement. Inside of a movieclip I switched the boolean and used the same keyboard interaction to walk through it. On the last frame of that movieclip, I switched the boolean back so the main timeline interaction kicked in again. The problem is, that's a Lot of copying and pasting of that code, and I can't figure out how to go through more than one parent. I just couldn't get it to work.


    Should I just be building this thing in a Completely different way? I need to make something, so for now I'm splitting up each frame that I need different animations on and creating a different movieclip for each section. Ideally that would be contained in one movieclip's timeline. Currently one each animation's interaction will be on a timeline. So I have to duplicate the slide to add an animation. So if I have a title come in, then a pie chart, then an image, then another piece of text, I'll be stuck with 4 separate movie clips.

    I'd love to figure out how to change that so it simply walks through the next frame of each movieclip if there is one.

    I want something like:
    if current movie clip current frame is == total frames, clicking right goes to next frame, else go to next frame of it's parent's timeline.

    I say the parent and not stage because the way you have to set up transitions only works within a movieclip. So you have to set up the entire slideshow within a movieclip if you want transitions between each slide. Right?
    I don't care about transitions for now, but will want control of those eventually.

    Any help is appreciated. I've searched quite a bit for this, but everything I found was basic. I learned a few little things each time, but nothing helped me enough to get me all the way.

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    How about adding a movieclip on the next frame? Like, hits the RIGHT arrow key, goes to next frame, and on that frame, the same layout and stuff from the previous frame is there, but and on that particular frame, a movieclip is added?
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    10
    well that's what I'm doing right now, but that's also what I'm trying to avoid.

    I don't want to have to duplicate each movieclip over and over. I'm guessing that would also make the file size much larger if I'm not careful to keep each element as a symbol instance?

    I'm trying to avoid this though because I will most likely have many changes. So every time someone changes a position of something on me, if there are 10 interactions on a page I'll have to update 10 pages? I'm not complaining about having to do some busy work, but I'd rather not waste time. Especially not if we are billing a client.


    I'm looking for an efficient solution that can easily be reused many times.

  4. #4
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Well, how about making a number variable. For example: limit = 5; and then, another variable for the current number: cur_number = 0; and then, if cur_number is equals to 0, first movieclip should play, and if it's 1, another movieclip should play, and when you perss a Key, cur_number should increase by one. You could use a code like this on each of your movieclip:

    Actionscript Code:
    onClipEvent(load){
        my_number = 2; // just change this
    }

    onClipEvent(enterFrame){
        if(_root.cur_number == my_number && this._currentframe == 1){
            // _currentframe == 1, will prevent this code from looping
            // after cur_number is equals to my_number
            this.play();
        }
    }

    Just copy the code above and paste it on each of your movieclip, and change my_number for each one, according to when they should start playing. And then, on your frame, assign a loop to keep checking if all movieclips have been played:

    Actionscript Code:
    onEnterFrame = function(){
        if(cur_number >= limit){
            play();
            delete onEnterFrame;
        }
    }

    When cur_number is equals to limit, in this case 5, it will start playing on your Main Timeline, going to nextFrame or whatever you want to. Get the concept?
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  5. #5
    Junior Member
    Join Date
    Aug 2011
    Posts
    10
    I'm not quite sure I understand how that works. That seems like it would play one after another, but only using the timeline as a control?
    I need to use the keyboard as a control to move to each action.

    That's the problem I'm having. Maybe this will be more clear.

    MovieClip Main timeline:
    1 2 3a 3b 3c 3d 4 5 6a 6b 7 8

    Where each number is a movieclip, and each letter is an action within the movie clip. The only frames I want in the MovieClip Main timeline are the numbers. I don't want to have to duplicate the frames with each action like I've got showing. That's what I have to currently do.

    I'd rather be able to walk through the timeline of each movieclip if multiple frames exist.

    Could I do something like, if current movieclip legth >= 1 then right arrow does movieclip.next frame and stop ?
    Yeah, I know that's not even close to what the code would be. I'd have to look it all up. But that's the general concept I'm thinking.

  6. #6
    Member
    Join Date
    Jul 2008
    Posts
    94
    Hey andy!

    Please excuse these very mucky examples, there are much neater ways of doing this

    If you have two movieclips and give them instance names of clip1 and clip2 (for example) did you know on the root timeline you can get their frames by saying:

    Actionscript Code:
    trace(clip1._totalframes);
    trace(clip2._totalframes);

    if you want to use the number of frames, then obviously you would use that value rather than just trace it. You can also set variables inside of each movie clip, so for instance, you could say

    Actionscript Code:
    clip1.isonthelastframe = false

    then you can have an if statment that says (everytime you press next)

    Actionscript Code:
    if(clip1.isonthelastframe == true)
    {
      //move the root timeline to the next frame

      //also, you would reset your values here, so it works next time as well
      clip1.isonthelastframe = false
    }
    else
    {
      if(clip1._currentframe == clip1._totalframes -1)
      {
        //go to the next frame of the clip
        clip1.isonthelastframe = true
      }
      else
      {
        //go to the next frame of the movie clip, but don't change anything else
      }
    }

    So, this is saying: When you press next, go to the next frame of the movieclip - unless you are on the last frame of the movieclip - then go to the next frame of the _root timeline. If you are on the frame before last, go to the next frame of the movieclip but change the isonthelastframe variable to true, so when you next click, the whole timeline will move on.


    I hope this helps, this isn't THE answer, but i really hope it gets you close

    dave
    Last edited by sheepysheep60; 08-18-2011 at 11:29 AM. Reason: made a few edits to my many errors!

  7. #7
    Junior Member
    Join Date
    Aug 2011
    Posts
    10
    The only issue I see here would be i would have to write a mega if else statement including every movie clip every time I want to create a new presentation. I suppose I could do some sort of array and ensure every movieclip is named carefully, but that's not ideal either.

    Hmmm, is there a way to just get a movieclip name from a current frame of another movieclip? I'm thinking no.

    So i suppose I could just do a series of movieclips that makes sense like "page1_mc" "page2_mc" etc. Put those into an array and instead of having my current:
    movieClip.gotoAndStop(movieClip.currentFrame+1) I'd have to have it add a child movie clip instead, even if it's one frame. Then inside of that, like you said, pass a variable noting the end.

    I haven't had any luck with something like that though. I'm not sure how to go about building that function.

  8. #8
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    I'm not really sure what you mean, but here is an EXAMPLE FILE of what I meant with my previous post!

    As you can see in the example file, in each presentation slide/frame, you only change the limit, and the limit should be equals to how many movieclips you want to play. And on each movieclip, there is the same actionscript code snippet, you only change my_number variable, which decides which one should start first. So, the first movieclip should have my_number set to 1, while the second 2, and so on. The code on the top-most layer is a listener. It listens to whenver you hold down a key, and when it's the RIGHT key, it will check if cur_number is greater than or equals to limit, and if it is, it should goto next frame, but if it's not, then it should increase the cur_number, so that other movieclips starts to play. If you were using onClipEvent(enterFrame) Key.isDown code, then don't do it, because it will simulate multiple right keys at once, making the Flash skips alot of frames/movieclips. Hope this is what you want, because it's pretty easy. If you want to add another movieclip, which you may have forgotten, you can easily add a new one, paste the same code to it, only increase my_number by one, and change limit variable - EASY
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  9. #9
    Junior Member
    Join Date
    Aug 2011
    Posts
    10
    I haven't looked at the example yet but on you explaining it again I saw it in a better way in my head, so I totally understand now.

    I think that works. I'm already half way into this one, but if there's time before the due date I'll definitely see if I can rework it in that way.

    I'm lucky in this presentation. He actually wants all of the elements on each page to be automatic so I don't have to do a bunch of duplicating work for each action. Everything is just timed out in it's own movieclip with a stop command at the end.

    Pretty simple stuff for this one, but I know I need to learn to move to the next steps.

    Thanks so much for the help. I'll key in again next week if I'm still having troubles.

  10. #10
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    No, seriously, take a look at the example. It only takes a few seconds :P
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  11. #11
    Junior Member
    Join Date
    Aug 2011
    Posts
    10
    OK, I found some time, looked. I think it will work, but that's quite a bit of code scattered throughout the file.

    I'd like to figure out if there's a way to keep most all of the code in the root still.

  12. #12
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Instead of all those codes, use this single code on a Frame:

    Actionscript Code:
    stop();

    frames = [3, 2, 0]; // how many movieclips, where 3 is Frame 1, etc.
    current_frame = 1;
    current = 0;

    rightKey = new Object();
    rightKey.onKeyDown = function(){
        if(Key.isDown(Key.RIGHT)){
            if(current >= _root.frames[current_frame-1] && _root._currentframe != _root._totalframes){
                _root.nextFrame();
                current_frame++;
                current = 0;
            } else {
                current++;
            }
        }
    }
    Key.addListener(rightKey);

    function play_movieclip(mc, i){
        mc.my_number = i;
        if(_root.current == mc.my_number && mc._currentframe == 1){
            mc.play();
        }
    }

    On the frames array, the numbers indicate how many movieclips on each frame. Since there are three numbers, it means that I've typed the amount of movieclips for three frames. Simply add another number for another frame, and there, type the amount of movieclips to be played. And then, on each movieclip, use this short code snippet to trigger them:

    Actionscript Code:
    onClipEvent(enterFrame){
        _root.play_movieclip(this, 1);
    }

    Change 1 to when the movieclip should play. 1 means that it should play after pressing RIGHT arrow once, and if you copy and paste the same snippet on another movieclip, but change 1 to 2, it will be triggered after 2 RIGHT arrow keys!

    NOTICE: With this code, you'll have to have a stop(); at the first frame and the last frame of your movieclip!
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  13. #13
    Junior Member
    Join Date
    Aug 2011
    Posts
    10
    I just wanted to update this project and show you a bit more of what I'm looking for.

    This isn't quite done but it's what I'm using for now. I had to go back a version and forgot to add the other keyboard inputs in. I need to add page up/down interaction so we can use powerpoint remotes. I can't believe those cost more than a couple bucks. It Only does page up/down on a remote. That's it. And some of them come with a laser pointer, oooooo.

    Code:
    import fl.transitions.*;
    
    // USER CONFIG SETTINGS
    
    var transitionOn:Boolean = true; // true, false
    var transitionType:String = "Fade";
    var fadeDuration:Number = .5; //this is the duration of the fade, in seconds. Default is 1 second if no value is given. 
    
    
    // END USER CONFIG SETTINGS
    
    // EVENTS
    
    
    	stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_changeSlideKeyboard);
    	function fl_changeSlideKeyboard(evt:KeyboardEvent):void
    	{
    		if(evt.keyCode == 37) // LEFT
    		{
    			fl_prevSlide();
    		}
    		else if (evt.keyCode == 39 || evt.keyCode == 32) // RIGHT OR SPACE
    		{
    			fl_nextSlide();
    		}
    	}
    	function fl_prevSlideButton(evt:MouseEvent):void
    	{
    		fl_prevSlide();
    	}
    	function fl_nextSlideButton(evt:MouseEvent):void
    	{
    		fl_nextSlide();
    	}
    
    
    // END EVENTS
    
    // FUNCTIONS AND LOGIC
    function fl_prevSlide():void
    {
    	if(slides_mc.currentFrame > 1)
    	{
    		slides_mc.gotoAndStop(slides_mc.currentFrame-1);
    		if(transitionOn == true)
    		{
    			fl_doTransition();
    		}
    	}
    }
    function fl_nextSlide():void
    {
    	if(slides_mc.currentFrame < slides_mc.totalFrames)
    	{
    		slides_mc.gotoAndStop(slides_mc.currentFrame+1);
    		if(transitionOn == true)
    		{
    			fl_doTransition();
    		}
    	}
    }
    
    function fl_doTransition():void
    {
    	if (transitionType == "Fade")
    	{
    		TransitionManager.start(slides_mc, {type:Fade, direction:Transition.IN, duration:fadeDuration});
    	}
    }
    
    slides_mc.gotoAndStop(1);
    stop();
    stage.scaleMode = StageScaleMode.SHOW_ALL;
    // END FUNCTIONS AND LOGIC
    I'm really only going to use the fade transition so that's no big deal. But that's why everything has to live in one main movieclip and not the main timeline. Each frame from there is another movieclip, unless it does Nothing.

    My challenge here is if I want one page to basically have 2 interactions, then I would prefer to have the keyboard entry walk through that timeline.

    I'd like All of the code, other than stop commands and animation controlled by AS, if any, to be in the main timeline. That's currently what I have. I currently don't have any other scripts other than Stop on the last frame of any clips with animation. Come to think of it, I should probably put a stop command on other ones too so they don't waste computing the same frame at 24fps. I forgot that it might do that.

    I was semi-lazy to leave the Fade string in there, but I thought it was a good reminder later in case I ever wanted to change it so I didn't have to search for it.
    That's why I created the fadeDuration variable. I hate searching through code to change something so simple like how long you want a transition.

  14. #14
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Oh, Actionscript 3.0 - I don't use it :/

    I recommend you use the Flash Slide Presentation Template.
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  15. #15
    Junior Member
    Join Date
    Aug 2011
    Posts
    10
    That Is the flash template. I just changed it.

    Also, your 16 and you decided to learn AS2? Flash is already barely holding on. Why did you choose to learn an even Older version? Only had an old version of flash to play with?

  16. #16
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    No, lol :P

    I started using Flash back when I was 11 years old, and it started with animation and basic actionscript like gotoAndStop and stuff like that, and I had Flash 8, and Actionscript 2.0 was the latest version, so yeah, I've been REALLY used to it :P
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

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