Results 1 to 4 of 4
  1. #1
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed

    [Collection]Snippets Vault[Flash]

    Use this format for submitting snippets

    It may be used later to parse the snippets to a application (like the one in the VB Section)

    If you're going to post a snippet in this thread then you should be posting it in the following format:

    Snippet Name: ____________________
    Keywords: ____,____,____ ...
    Description(Optional): _______________________
    Code:
    Code:
    Your Code Here...
    This is to be used for any small bit of code you would like to share.




     


     


     



    The Most complete application MPGH will ever offer - 68%




  2. The Following User Says Thank You to NextGen1 For This Useful Post:

    poppin911 (10-10-2011)

  3. #2
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Snippet Name: Shuffle Array (Action Script 3)
    Keywords: Flash,Shuffle,Array,AS3
    Description: This reorders the elements of an array into a random order.
    Code:
    var anArray:Array = [1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4];
    anArray=shuffleArray(anArray);
    
    function shuffleArray(arr:Array):Array{
     var arr2:Array = [];
     while (arr.length > 0){
      arr2.push(gendersArray.splice(Math . round(Math.random() * (arr.length - 1)), 1)[0]);
     }
     return arr2;
    }
    Snippet Name: Convert a String into an Array Using Action Script 3
    Keywords: String To Array, AS3
    Description: Converts the string into an array using the actionscript "split" function.
    Code:
    //the string to turn into an array
    var arrayString:String="1,2,3"; 
    //convert the string to an array using the "," as a divider (aka delimiter)
    var newArray:Array= arrayString.split(",")  
    //convert the array items from strings to numbers
    var n=newArray.length;
     while (n--) {
      newArray[n]=Number(newArray[n])
     }
    trace(String(trainCubesArray[0]+1));

    Snippet Name:
    Detecting when mouse leaves stage.
    Keywords: Mouse Detection, AS, Flash, Rollover, Hover
    Description: This is how you detect if the mouse leaves Flash and rolls over to web page:
    Code:
    var c:Sprite = new Sprite();
    c.graphics.beginFill(0xFF);
    c.graphics.drawRect(0, 0, 200, 200);
    addChild(c);
    stage.addEventListener(Event.MOUSE_LEAVE, cursorHide);
    //there is no mouse exit so you need to use this
    stage.addEventListener(MouseEvent.MOUSE_MOVE, cursorFollow);
    function cursorHide(evt:Event):void {
     c.alpha=.2
    }
    function cursorFollow(evt:MouseEvent):void {
     c.alpha=1
     evt.updateAfterEvent();
    }


    Snippet Name:Blur Using AS3
    Keywords: Blur,Flash,AS3,AS4
    Description:Creates a blur effect on movie clips.
    Code:
    var blur:BlurFilter = new BlurFilter();
    blur.blurX=20;
    blur.blurY=20;
    blur.quality=BitmapFilterQuality.LOW;
    displayObjectToBlur_mc.filters=[blur];
    Snippet Name:AS3 full screen mode
    Keywords: AS3, FullScreen, Mode
    Description:Toggles full screen mode using AS3.
    Code:
    function toggleFullScreenMode(e:MouseEvent):void {
     if (viewingFullScreen==false) {
      viewingFullScreen=true;
      navsNorthMultiPage_mc.tween_mc.eastButtons_mc.fullScreenAnim_mc.gotoAndPlay("full");
      navsSouthMultiPage_mc.tween_mc.eastButtons_mc.fullScreenAnim_mc.gotoAndPlay("full");
      stage.displayState="fullScreen";
     } else {
      viewingFullScreen=false;
      navsNorthMultiPage_mc.tween_mc.eastButtons_mc.fullScreenAnim_mc.gotoAndPlay("out");
      navsSouthMultiPage_mc.tween_mc.eastButtons_mc.fullScreenAnim_mc.gotoAndPlay("out");
      stage.displayState="normal";
     }
    }
    Snippet Name:AS3 Disable Yellow Tab Rectangles
    Keywords:Disable, AS3, Tab, Rectangles
    Description:Are you wondering why when you hit tab in your Flash site you get those nasty yellow rectangles around your links? Here's how to disable them:

    If you have a movieclip with a bunch of buttons inside it and you want to disable all of them with one line of code use this:

    Code:
    MC_Container_Name.tabChildren = false;
    Or to just disable the yellow box on a single movieclip use this:

    Code:
    MC_Name.tabEnabled = false;
    Snippet Name:AS3 Smooth Loaded Bitmaps
    Keywords:AS3,Smooth,Loaded,Bitmaps
    Description: Loaded bitmaps (jpgs, pngs, etc) look bad in flash when scaling unless you smooth them. This function seems to replicate the bitmap "smoothng" setting in the library pallette. I still see tons of Flash sites out there that arent aware of this awesome setting. It makes bitmaps look great when they scale.
    Code:
    //create a new loader object and put it on the stage
    var slideLoader:Loader=new Loader();
    this.addChild(slideLoader);
    
    //load picture into loader object
    slideLoader.contentLoaderInfo.addEventListener(Even*****MPLETE, scaleContentForPicture);
    slideLoader.load(new URLRequest("https://www.mpgh.net/forum/images/tree.jpg"));
    
    //smooth it once loaded
    function scaleContentForPicture() {
    var smoother_bm=Bitmap(slideLoader.content);
    smoother_bm.smoothing=true;
    }
    Snippet Name:Slideshow with autoplay and reset delay
    Keywords:AS3,Slideshow,autoplay
    Description: This code starts with a long pause then starts looping through images. If the user interacts with the slideshow, the timer is reset then starts playing again later if the user hasnt interacted.
    Code:
    var resetTime:uint=5000;
    var pauseBetweenSlides:uint=5000;
    var slideCounter:uint=1;
    var prevSlide:uint=0;
    
    var startShowTimer:Timer=new Timer(resetTime,1);
    startShowTimer.addEventListener(TimerEvent.TIMER, setUpTimer);
    var slideShowTimer:Timer=new Timer(pauseBetweenSlides,0);
    slideShowTimer.addEventListener(TimerEvent.TIMER, autoAdvance);
    
    //auto advance
    function autoAdvance(e:TimerEvent):void {
     nexttSlide();
    }
    
    //next
    function nexttSlide():void {
     prevSlide=slideCounter;
     slideCounter++;
     if (slideCounter==6) {
      slideCounter=1;
     }
     goToSlide();
    }
    //prev
    function prevvSlide():void {
     prevSlide=slideCounter;
     slideCounter--;
     if (slideCounter==0) {
      slideCounter=5;
     }
     goToSlide();
    }
    //display next slide and hide previous
    function goToSlide():void {
     slideshow_mc["slide"+slideCounter+"_mc"].gotoAndPlay("show");
     if (prevSlide>0) {
      slideshow_mc["slide"+prevSlide+"_mc"].gotoAndPlay("hide");
     }
    }
    //pause slideshow and reset timer
    function resetTimer():void {
     slideShowTimer.stop();
     startShowTimer.reset();
     startShowTimer.start();
    }
    //called when reset pause is finished
    function setUpTimer(e:TimerEvent):void {
     startShowTimer.reset();
     slideShowTimer.start();
    }
    
    
    resetTimer();
    goToSlide();
    
    
    //Controls--------
    function showControls():void {
     slideShowPrev_mc.gotoAndPlay("show");
     slideShowNext_mc.gotoAndPlay("show");
    }
    function hideControls():void {
     slideShowPrev_mc.gotoAndPlay("hide");
     slideShowNext_mc.gotoAndPlay("hide");
    }
    
    
    
    slideShowNext_mc.addEventListener(MouseEvent.CLICK, invokeNextSlide);
    function invokeNextSlide(e:MouseEvent):void {
     resetTimer();
     nexttSlide();
    }
    slideShowPrev_mc.addEventListener(MouseEvent.CLICK, invokePrevSlide);
    function invokePrevSlide(e:MouseEvent):void {
     resetTimer();
     prevvSlide();
    }
    Last edited by Hassan; 10-22-2010 at 03:20 PM.

  4. The Following 2 Users Say Thank You to Hassan For This Useful Post:

    Euphemistic (10-19-2013),NextGen1 (10-22-2010)

  5. #3
    poppin911's Avatar
    Join Date
    Oct 2011
    Gender
    male
    Location
    El Cerrito, CA, USA
    Posts
    84
    Reputation
    10
    Thanks
    8
    My Mood
    Bashful
    @Hassan do u know Adobe Dreamweaver?

  6. #4
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Yes, I do lol. Why ?

Similar Threads

  1. [Collection]Snippets Vault[C#]
    By NextGen1 in forum C# Programming
    Replies: 21
    Last Post: 10-13-2019, 10:48 AM
  2. [Source Code] Snippets Vault
    By NextGen1 in forum Visual Basic Programming
    Replies: 112
    Last Post: 06-14-2019, 07:51 PM
  3. [Collection]Snippets Vault[PHP]
    By NextGen1 in forum PHP Programming
    Replies: 13
    Last Post: 10-13-2018, 09:10 PM
  4. [Collection]Snippets Vault[Assembly]
    By NextGen1 in forum Assembly
    Replies: 5
    Last Post: 11-05-2012, 01:10 AM
  5. [Collection]Snippets Vault[D3D]
    By NextGen1 in forum DirectX/D3D Development
    Replies: 0
    Last Post: 09-28-2010, 08:36 AM