1

i want to make a scrollable index of particular math book for android version where i will be able to scroll a movie clip consists of 56 child movieclips(there are chapter 1 to chapter 56 child clips has made "buttons_all" parentclip) and when i will choose a child movie clip it will go to selected label or chapter(suppose if i click chapter 1 movie clip it will gotoAndPlay("chapter 1")).i had made the parent movieclip scrollable and added eventlistener to each child movie clip..but when i want to scroll it is doing two things,first it scrolls then go to that "chapter" that i clicked to start scrolling whether i want to go this chapter or not.to solve that i added a timer event to create an interval to stop selecting chapter immediately before i want to select a specific chapter..but it is working partially.i want to add this interval to every button.because i dont have a scrollbar here for up and down..please help me to solve this..here is my part of code

 var pat1:MovieClip = scrolling_manu.buttons_all.part1;

    var listTimer:Timer; // timer for all events

     var tapDelayTime:Number = 0;
     var maxTapDelayTime:Number = 20; // change this to increase or descrease tap sensitivity

     var tapEnabled:Boolean = false;

 init();
 function init()
    {
        //removeEventListener(Event.ADDED_TO_STAGE, init);

        pat1.addEventListener(TouchEvent.TOUCH_BEGIN, onmouseDown );
        //trace("hit");

         pat1.addEventListener(TouchEvent.TOUCH_END, onmouseUp );
        listTimer = new Timer( 33 );
        listTimer.addEventListener( TimerEvent.TIMER, onListTimer);
        listTimer.start();

    }
    function onmouseDown( e:TouchEvent ):void 
    {

         handleItemPress()
    }
    function onmouseUp( e:TouchEvent ):void 
    {

        onTapDisabled();
        //listTimer.stop();
    }

 function onListTimer(e:Event):void
    {
        // test for touch or tap event
        if(tapEnabled)
            onTapDelay();


    }


    function onTapDisabled():void
    {

            tapEnabled = false;
            tapDelayTime = 0;

    }       
function onTapDelay():void

    {
        tapDelayTime++;

        if(tapDelayTime > maxTapDelayTime ) 
        {
            //tapItem.selectItem();
            tapDelayTime = 0;
            tapEnabled = false;
            trace("hit");
            pat1.gotoAndPlay("over1");
            pat1.addEventListener(TouchEvent.TOUCH_END, onmouseUp );
        }

    }

    function handleItemPress()
    {
            tapDelayTime = 0;
            tapEnabled = true;
            trace("hit");

    }
USERRR5
  • 430
  • 2
  • 10
  • 27

1 Answers1

0

Firstly, I recommend you to convert all vector images to raster. It's very hard for processor to animate vector images.

Delete all code after drop_me function.

Write this:

scrolling_manu.buttons_all.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
scrolling_manu.buttons_all.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);

var touchedPart:MovieClip;
var posY:int;

function onTouchBegin(event:TouchEvent):void
{
    touchedPart = event.target as MovieClip;
    posY = scrolling_manu.buttons_all.y;
}

function onTouchEnd(event:TouchEvent):void
{
    // if list was been moved, that isn't a tap.
    if (posY == scrolling_manu.buttons_all.y)
    {
        trace("part tapped", touchedPart.name);
        touchedPart.gotoAndPlay("over1");
    }
}
Daniil Subbotin
  • 6,138
  • 5
  • 20
  • 24
  • [Here](https://gist.github.com/subdan/724721f54195b7ff4f9a) it's all code that you should copy to frame 1 of layer "local action". – Daniil Subbotin Feb 18 '15 at 10:43
  • Do you want to cut digit 12 from string "part12"? Try this: `var n:String = touchedPart.name; var index:int = n.match(/\d+/)[0]; trace("part tapped", index);` – Daniil Subbotin Feb 19 '15 at 07:24
  • your idea works but i don't want to cut 12 digit from string "part12" .in my project i have 40 buttons(child movie clips(part1,part2,part3......)that you saw) and 40 frame labels("part1","part2","part3"......) i want part 1 Movieclip is connected to part1 frame label same as part2 to part2 frame label .......i want when i click to part1 Movie clip it will go to part1 frame label to play an animation or if i click part2 Movie clip it will go to part2 frame label ...is it possible to keep movie clips and frame label in array and matching them and play them with the button click? – USERRR5 Feb 19 '15 at 09:41
  • 12 it's an example. You can cut either digit. – Daniil Subbotin Feb 19 '15 at 09:44
  • `touchedPart.name` it's a name of touched item (ex. part3). Expression `match(/\d+/)[0]` returns digit after `part` word. So you can write `gotoAndStop("part" + index)`. – Daniil Subbotin Feb 19 '15 at 09:48