Skip to main content
Known Participant
February 21, 2014
Question

function issue

  • February 21, 2014
  • 1 reply
  • 354 views

i have a package containg function "Main".

in frame one i have movieclip with scroll script and child of this movieclip, as well as a btn that trigger "gotoandstop(2)" ,frame 2  contains video, and a btn "return" that trigger "gotoandstop(1)" (back to frame 1).

however when returning to frame one the movie clip loses the scroll and child is not added.

what is my mistake?

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
February 21, 2014

What is the function issue that titles your posting?  What does it have to do with adding the scroll and the child to the movieclip?  You should show the code that is involved with your issue.

udikAuthor
Known Participant
February 22, 2014

this is the code:

the  public function resumeVideo  activates"gotoandstop(1)".

on frame 1 i want all the app to start again (including of course the

  scroll_mc.addChild(A1)

  scroll_mc.addChild(A2)

located in function Main

thank you

package {

          import fl.containers.ScrollPane;

          import fl.controls.ScrollPolicy;

          import flash.desktop.NativeApplication;

          import flash.desktop.SystemIdleMode;

          import flash.display.MovieClip;

          import flash.media.Video;

          import flash.net.NetConnection;

          import flash.net.NetStream;

          import flash.events.MouseEvent;

          import flash.events.NetStatusEvent;

          import fl.controls.List

          import flash.events.Event;

                    public class Main extends MovieClip {

                    public var song:Array=["lego.flv","hatizmoret.flv","shir_hageshem.flv","ez.flv", "tarnegol.flv","se_ugdi.flv","dag.flv","lizard.flv","toy_train_set_qt. flv","hadubim.flv","geveret_shfanfana.flv",

                                             "parash_ben_hail.fl v","snake.flv","pil_pilon.flv","cat.flv","gan_shelanu.flv","purrfect_b irthday_qt.flv","nadneda.flv","hatul_ganav.flv",

                                             "yonatan_hakatan.fl v","dog.flv","aviron.flv","zipor.flv","hipo.flv","ladod_moshe.flv","sh afan.flv","hipushit.flv","achbar.flv","tolaat.flv","zefardea.flv","dov .flv",

                                             "shaon_ben_hail.flv ","kof.flv","hayom_yom_huledet.flv","ima_yekara.flv","oniya.flv","bee_ and_flowers_qt.flv ","hasida.flv","ima_avaza.flv","yedidi_tintan.flv","donkey.flv",

                                             "haoto_shelanu.flv" ,"bimdinat_hagamadim.flv"]

                    public var song_number:String

                    public var netConnection:NetConnection;

                    private var netStream:NetStream;

                    private var video:Video;

                    private var VIDEO_URL:String;

                    public var speed:Number;

                    public var speedArray:Array;

                                                                      public var prevY:Number;

                    public var DRAG:Number = 20;

                    public var HEIGHT:int = 310;

                    public var posX:int= 10;

                    public var posY:int =10;

                    public var widt:int=100;

                                                                   public var high:int=100

                                                                   public var A1:MovieClip=new a1()

                    public var A2:MovieClip=new a2()

                    public var scroll_mc:MovieClip

 

 

                    public function Main() {

                                                            scroll_mc.addChild(A1)

                                                            scroll_mc.addChild(A2)

                                          A1.x=posX

                                          A1.y=posY

                                                            A1.height=high;

                                                            A1.width=widt;

 

            A1.addEventListener(MouseEvent.CLICK, next_frame1);

            A2.x=(posX +110)

            A2.y=posY

            A2.height=high;

            A2.width=widt;     

                                                            A2.addEventListener(MouseEvent.CLICK, next_frame2);           

                              scroll_mc.addEventListener(MouseEvent.MOUSE_DOWN, onDown);

                              NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;

                              netConnection = new NetConnection();

                              netConnection.connect(null);

                              netStream = new NetStream(netConnection);

                              netStream.client = this;

                              netStream.addEventListener(NetStatusEvent.NET_STATUS, statusUpdated);

                              video = new Video();

                              video.attachNetStream(netStream);

                              video.width = 480;

                              video.height = 320;

                              addChildAt(video, 0);

                    }

                                                  public function next_frame1(e:MouseEvent):void {

                                                            gotoAndStop(2)

                                                            song_number=song[0]

                                                            setupControls();

 

                                                            trace(VIDEO_URL)

                                                            trace(song_number)

                                                  }

 

                                                  public function next_frame2(e:MouseEvent):void {

                                                            gotoAndStop(2)

                                                            song_number=song[1]

                                                            setupControls();

 

                                                  }

                    function onDown(evt:MouseEvent):void {

                    speedArray = new Array(0,0,0,0,0,0,0,0,0,0);

                    speed = 0;

                    prevY = this.mouseY;

                    stage.addEventListener(Event.ENTER_FRAME, onDownEnter);

                    stage.addEventListener(MouseEvent.MOUSE_UP, onUp);

                    }

                    function onDownEnter(evt:Event):void {

                    var sp = this.mouseY - prevY;

                    scroll_mc.y += sp;

                    if (scroll_mc.y < (HEIGHT-scroll_mc.height)) {

                    scroll_mc.y = (HEIGHT-scroll_mc.height);

                    }

                    else if (scroll_mc.y > 0) {

                    scroll_mc.y = 0;

                    }

                    speedArray.push(sp);

                    speedArray.shift();

                    prevY = this.mouseY;

                    }

                    function onUp(evt:MouseEvent):void {

                    stage.removeEventListener(Event.ENTER_FRAME, onDownEnter);

                    stage.removeEventListener(MouseEvent.MOUSE_UP, onUp);

                    speed = 0;

                    for (var i:int = 0; i<speedArray.length; i++) {

                    speed += speedArray;

                    }

                    speed /= speedArray.length;

                   

                    addEventListener(Event.ENTER_FRAME, onEnter);

                    }

                    function onEnter(evt:Event):void {

                    if (Math.abs(speed) < .5) {

                    speed = 0;

                    }

                    if (speed < 0) {

                    if (scroll_mc.y > (HEIGHT-scroll_mc.height) - speed) {

                    scroll_mc.y += speed;

                    speed -= speed/DRAG;

                    }

                    else {

                    scroll_mc.y = (HEIGHT-scroll_mc.height);

                    speed = 0;

                    }

                    }

                    else {

                    if (scroll_mc.y < 0-speed) {

                    scroll_mc.y += speed;

                    speed -= speed/DRAG;

                    }

                    else {

                    scroll_mc.y = 0;

                    speed = 0;

                    }

                    }

                    }

                    public function itemClick(event:Event):void{

                             

                              setupControls();

                   }

                    public function onMetaData(dataObj:Object):void {

                              ; // Do nothing.

                    }

                    public function onXMPData(dataObj:Object):void {

                              ; // Do nothing.

                    }

                    public function statusUpdated(e:NetStatusEvent):void {

                              if(e.info.code == "NetStream.Play.Stop")

                              {

                                        showBtns(["playBtn"]);

                              }

                    }

                    public function setupControls():void {

                    controls.playBtn.addEventListener(MouseEvent.MOUSE_UP, playVideo);

                    controls.restartBtn.addEventListener(MouseEvent.MOUSE_UP, restartVideo);

                    controls.resumeBtn.addEventListener(MouseEvent.MOUSE_UP, resumeVideo);

                              stage.addEventListener(MouseEvent.MOUSE_UP, pauseVideo);

                              showBtns(["playBtn"]);

                    }

                                                  public function playVideo(e:MouseEvent):void {

                                                            VIDEO_URL = "http://www.tovale.co.il/ktantanim/"+song_number

                                                            netStream.play(VIDEO_URL);

                                                            hideBtns();

                                                            e.stopPropagation();

                                                            trace(VIDEO_URL)

                                                            trace(song_number)

                  }

                    public function pauseVideo(e:MouseEvent):void {

                              if(controls.visible == false)

                              {

                                        netStream.pause();

                                        showBtns(["resumeBtn", "restartBtn"]);

                              }

                    }

                    public function restartVideo(e:MouseEvent):void {

                              netStream.seek(0);

                              netStream.resume();

                              hideBtns();

                              e.stopPropagation();

                    }

                    public function resumeVideo(e:MouseEvent):void {

                             // netStream.resume();

                                                                      

                                                                       netStream.close()

                                                                       video.clear()

                             hideBtns();

                             e.stopPropagation();

                                                                       gotoAndStop(1)

                                                                       next_frame2(e:MouseEvent):void

                                                                      

                                                                      

                    }

                    public function hideBtns():void {

                              controls.visible = false;

                              blocker.visible = false;

                    }

                    public function showBtns(btns:Array):void {

                              controls.visible = true;

                              blocker.visible = true;

                              for(var instName:String in controls)

                              {

                                        if(btns.indexOf(instName) != -1)

                                        {

                                                  controls[instName].visible = true;

                                        }

                                        else

                                        {

                                                  controls[instName].visible = false;

                                        }

                              }

                    }

                                                  }

}