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

Add navigation buttons on top of every scene

Explorer ,
May 14, 2014 May 14, 2014

Hello,

I've got a Flash movie with quite a few scenes and I'd like to add navigation buttons (prev\next) with AS3 to move from scene to scene.

Sounds easy but...

If I write this on first frame of first scene :

this.addChild(play_btn);

buttons will appear OK on this first scene but will disappear under objects of the second scene

If I change to

stage.addChild(play_btn);

button will appear OK over every scene but, as my SWF is loaded in an e-learning software that produces SWF, the buttons will remain on the "stage" of every slide of the final module ! I can't remove them when the user changes slide because I can't run AS3 when changing slide...

Is there way of adding the buttons "inside" my movie but on top of everything that might appear afterwards ? No more depth or Z order in AS3 ?

Thanks.

Please don't tell me using scenes is bad because I've been using them for years and I've always read that all scenes become a long timeline at runtime. They're just very handy to me.

TOPICS
ActionScript
709
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
LEGEND ,
May 14, 2014 May 14, 2014

In AS3 you work with indexes of the display list rather than depths (never was a Z order in any AS version that I know of).  If you want to have an object at a certain index then you can assign it there using addChildAt() or setChildIndex().  0 is the lowest in the order of things and numChildren-1 is the current highest.  If you want to add things within other things then you can use otherthings.addChild(things); (or use the addChildAt)

But since you are adding them dynamically to a timeline based design, using scenes, if you place them inside an object in one scene, they will not be there when you move to the next scene like they are now.  That's not the reason scenes are not a recommended design choice, but it is another issue with using them.  Scenes just don't work reliably when it comes to designs that involve navigating between them. 

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
Explorer ,
May 16, 2014 May 16, 2014

Thanks for your answer Ned.

The problem is I would like to add buttons to the highest level from the start but it seems you can't do it in AS3 (no gaps in index) when you could set whatever depth you wanted in AS2. What puzzles me is that scenes are supposed to merge into a long timeline so the highest index should be set from the start !?

Maybe I could add a timer that would check and put buttons on top level ?

I also read about "containers" but I'm too new to AS3 to go that way.

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
LEGEND ,
May 16, 2014 May 16, 2014

indexes work nearly the same as depths do in AS2 - except that you can't assign to an index that is greater than the number of children - 1.  I believe in AS1/2 you can set a depth at any value.

You can place an object at any index (consider it depth) you choose as long the index does not exceed the number of children that are involved.  You can swap indexes oif objects, much the same way you would swapDepths in AS2 (I believe there is a swapChildren method available too).

I am willing to bet that whatever you are trying to do that resembles what you would do in AS2 can be done.  A container can be as simple as a movieclip or sprite to which you add another object... I am pretty sure you would have done this in AS2 but just never thought about things as conatiners.  A container is simply an object that contains another, and as a container it has various supporting methods and properties for that purpose.

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
Explorer ,
May 16, 2014 May 16, 2014
LATEST

  I believe in AS1/2 you can set a depth at any value.

Yes ! And that would have been handy here... not clean, but handy !

Here's what I did so far :

I added the buttons to the root and found a function that did the trick, called with a timer :

var play_btn:mcBtnPlay = new mcBtnPlay();

Object(root).addChild(play_btn);

...

function moveToTop(child:DisplayObject):void {

  (child.parent != null) ? child.parent.setChildIndex(child, child.parent.numChildren-1) : null;

}

....

function timerListener(e:TimerEvent):void {

  moveToTop(play_btn);

The only problem is that the buttons will flash on screen at scene change because the of the timer interval, but you can think it's on purpose (visual clue) .

Don't know if there's a more clever way to detect scene change apart from some code on each first frame of scenes ?

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