Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    creare una funzione con f5

    Ciao ragazzi,
    partendo da questo codice che devo inserirlo ogni volta su un mc, volevo creare una funzione.
    onClipEvent (load) {
    newX = Math.round(Math.random()*200);
    accelFactor = Math.ceil(Math.random()*4)+2;
    }
    onClipEvent (enterFrame) {
    currentlocx = this._x;
    differencex = newX-currentlocx;
    accelx = differencex/accelFactor;
    this._x = this._x+accelx;
    if (Math.round(this._x) == Math.round(newX)) {
    newX = Math.round(Math.random()*200);
    accelFactor = Math.ceil(Math.random()*4)+2;
    }
    }
    Io ho provato cosi' ma l'oggetto parte e non si vede più.
    function reset(theClip) {
    theClip.newX = theClip.Math.round(theClip.Math.random()*200);
    theClip.accelFactor = theClip.Math.ceil(theClip.Math.random()*6)+2;
    }
    function fade(theClip) {
    theClip.currentlocx = theClip._x;
    theClip.differencex = theClip.newX-theClip.currentlocx;
    theClip.accelx = theClip.differencex/theClip.accelFactor;
    theClip._x = theClip._x+theClip.accelx;
    if (theClip.Math.round(theClip._x) == theClip.Math.round(theClip.newX)) {
    theClip.newX = theClip.Math.round(theClip.Math.random()*200);
    theClip.accelFactor = theClip.Math.ceil(theClip.Math.random()*6)+2;
    }
    }

    Sul mc ho messo:
    onClipEvent (load) {
    _root.reset(this);
    }
    onClipEvent (enterFrame) {
    _root.fade(this);
    }



  2. #2
    fai prima a scrivere quel codice su un file di testo e salvarlo chiamandolo actionclip.as, poi sui clip scrivi solo

    #include "actionslip.as";


  3. #3
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    codice:
    function reset(theClip)
    {
    	theClip.newX = Math.round(Math.random() * 200);
    	theClip.accelFactor = Math.ceil(Math.random() * 6) + 2;
    }
    function fade(theClip)
    {
    	theClip.currentlocx = theClip._x;
    	theClip.differencex = theClip.newX - theClip.currentlocx;
    	theClip.accelx = theClip.differencex / theClip.accelFactor;
    	theClip._x = theClip._x + theClip.accelx;
    	if (Math.round(theClip._x) == Math.round(theClip.newX)) {
    		theClip.newX = Math.round(Math.random() * 200);
    		theClip.accelFactor = Math.ceil(Math.random() * 6) + 2;
    	}
    }
    Non devi mettere "theClip" davanti al Math.round.

  4. #4
    ehehe, fai ancora prima se fai come ha detto il sommo

  5. #5
    Grazie Nega
    funziona tutto, se gentilmente puoi spiegarmi il codice iniziale, perchè non devo mettere theClip davanti al Math.round è possibile far cambiere colore all'oggetto sempre utilizzando la funzione?


  6. #6
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    Perchè Math è un oggetto statico, non è un metodo della Classe MovieClip: quindi si usa sempre Math e basta, seguito dal metodo (nel caso, il metodo "round").

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.