Skip to main content
Known Participant
January 14, 2011
Question

keep package functions from starting automatically

  • January 14, 2011
  • 1 reply
  • 1008 views

hey everyone! this should be simple.

i've got a movie clip which i "exported for actionscript" inside of the properties dialog.

this is the code inside of the package that was created to go along with it (MovieClipName.as)

package {      import flash.display.MovieClip;      import flash.utils.Timer;      import flash.events.TimerEvent;      import flash.events.Event;      import flash.display.Loader;      import fl.transitions.Tween;      import fl.transitions.easing.*;      import fl.transitions.TweenEvent;      import flash.net.URLRequest;      import flash.display.Bitmap;      import flash.trace.Trace;      public class cont extends MovieClip      {           public var mCONTENT:Array=new Array();           public var mUBTIL:Array=new Array();           public var NOBAR:Boolean = false;           public var MASTER:Timer = new Timer(5000,1);           public var p:Number = 0;           public var q:Number = 1;           public var ChurnerI:Tween;           public var ChurnerII:Tween;           public var lod:Loader = new Loader();           public function startSlideshow()           {                trace("CONT IS ACTIVE!!!")                NOBAR=false;                MASTER.addEventListener(TimerEvent.TIMER, reportProcessComplete);                MASTER.start();                loadSequentialPictures();                function beginSlideshowLoop()                {                     if (NOBAR != true)                     {                          MASTER.start();                          loadSequentialPictures();                     }                }                function reportProcessComplete(e:Event)                {                     p++;                     if (p == 2)                     {                          p = 0;                          movePics();                     }                }                function reportMovementComplete()                {                     wrapper();                     beginSlideshowLoop();                }                function wrapper()                {                     q++;                     if (q == mCONTENT.length)                     {                          q = 0;                     }                }                function loadSequentialPictures()                {                     if (mCONTENT.length > 1)                     {                          if (mCONTENT is Bitmap)                          {                               mCONTENT.y = 0;                               mCONTENT.width = 857;                               mCONTENT.height = 512;                               mCONTENT.x = 857 + 2;                               stage.addChild(mCONTENT);                               reportProcessComplete(null);                          }                          else                          {                               loadSeqPic();                          }                     }                }                function loadSeqPic()                {                     var request:URLRequest = new URLRequest("http://www.jawilsonarchitects.biz/portphot/" + mCONTENT);                     lod= new Loader();                     lod.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, seqLoaded);                     lod.load(request);                }                function seqLoaded(e:Event)                {                     var JohnIII:Bitmap = Bitmap(lod.content);                     mCONTENT.splice(q,1,JohnIII);                     mCONTENT.y = 0;                     mCONTENT.width = 857;                     mCONTENT.height = 512;                     mCONTENT.x = 857 + 2;                     stage.addChild(mCONTENT);                     reportProcessComplete(null);                }                function movePics()                {                     ChurnerI = new Tween(stage.getChildAt(0),"x",Regular.easeInOut,stage.getChildAt(0).x,-857 - 2,15,false);                     ChurnerII = new Tween(stage.getChildAt(1),"x",Regular.easeInOut,stage.getChildAt(1).x,0,15,false);                     ChurnerII.addEventListener(TweenEvent.MOTION_FINISH, reset);                }                function reset(e:Event)                {                     stage.removeChildAt(0);                     reportMovementComplete();                }           }      } }

most of the code shouldn't matter. i'm new to packages and i just want to know how to keep startSlideshow() from triggering when a new instance of this movieclip is created. i would prefer if something like ThisMovieClip.startSlideshow() had to be triggered. please excuse my dorky labels, etc. thank you!

EDIT: oh! and it would be helpful if you could tell me how to add things to the inside of the movieclip from this package. i assumed adding it to the stage would do the trick but i haven't been able to test to find the right method yet. from the timeline i could just use Movieclip.addChild(picture) but i don't know how to do it from within the package. thanks again.

Message was edited by: JohnFour

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
January 14, 2011

just don't call that class method.

but i think you have nested named functions which is a major problem for you.  you need to unnest those functions.

JohnFourAuthor
Known Participant
January 14, 2011

it seems that i was missing a set of parenthesis that caused the function to be run right away? in any case i don't know what nested functions are, how to get rid of them, or why they are a problem. thanks

Participating Frequently
January 14, 2011

Nested functions are those functions inside another function.

In your case, all functions are inside you main function.

This is bad because you can't reach them from the outside of the wrap function (the function that have functions inside), and for another infinity set of things

And about the initial problem, did you solved it putting the missing parenthesis?

If you want your class being instantiated AND run right from the start, put a constructor function (a function with the same name of the class) on it.

If not, just don't do this.

(Confusing answer, I know!!)

And to address your edit, can you specify a little?

Do you want add images to this class or put the class on your stage?