Bouton de défilement pour du texte dynamique

Artscene Messages postés 5 Date d'inscription dimanche 22 mars 2009 Statut Membre Dernière intervention 19 avril 2009 - 18 avril 2009 à 23:57
Artscene Messages postés 5 Date d'inscription dimanche 22 mars 2009 Statut Membre Dernière intervention 19 avril 2009 - 19 avril 2009 à 15:22
Bonjour à tous,

Voila mon problème, je voudrais faire un bouton de défilement pour du texte dynamique, mais je ne trouve aucune aide. Effectivement, je me met seulement à l'AS3 et je ne comprend pas tout...
Donc voila mon code :

//Import TweenMax et de son plugin Blur
import gs.TweenMax;
import gs.plugins.BlurFilterPlugin;
 
//Taille du contenu et du masque
var CONTENT_HEIGHT:Number = 899;
var MASK_HEIGHT:Number = 250;
 
//We want to know what was the previous y coordinate of the content (for the animation)
var oldY:Number = myContent.y;
 
//Position the content on the top left corner of the mask
myContent.x = myMask.x;
myContent.y = myMask.y;
 
//Set the mask to our content
myContent.mask = myMask;
 
//Create a rectangle that will act as the bounds to the scrollMC.
//This way the scrollMC can only be dragged along the line.
var bounds:Rectangle = new Rectangle(scrollMC.x,scrollMC.y,0,250);
 
//We want to know when the user is scrolling
var scrolling:Boolean = false;

 
//This function is called when the user is dragging the scrollMC
function startScroll(event:Event):void {
 
    //Set scrolling to true
    scrolling = true;
 
    //Start dragging the scrollMC
    scrollMC.startDrag (false,bounds);
}
 
//This function is called when the user stops dragging the scrollMC
function stopScroll(event:Event):void {
 
    //Set scrolling to false
    scrolling = false;
 
    //Stop the drag
    scrollMC.stopDrag ();
}
 
//Listen when the user is holding the mouse down on the scrollMC
scrollMC.addEventListener(MouseEvent.MOUSE_DOWN, startScroll);
 
//Listen when the user releases the mouse button
stage.addEventListener(MouseEvent.MOUSE_UP, stopScroll);

//Add ENTER_FRAME to animate the scroll
addEventListener(Event.ENTER_FRAME, enterHandler);
 
//This function is called in each frame
function enterHandler(e:Event):void {
 
    //Check if we are scrolling
    if (scrolling == true) {
 
        //Calculate the distance how far the scrollMC is from the top
        var distance:Number = Math.round(scrollMC.y - bounds.y);
 
        //Calculate the percentage of the distance from the line height.
        //So when the scrollMC is on top, percentage is 0 and when its
        //at the bottom the percentage is 1.
        var percentage:Number = distance / MASK_HEIGHT;
 
        //Save the old y coordinate
        oldY = myContent.y;
 
        //Calculate a new y target coordinate for the content.
        //We subtract the mask's height from the contentHeight.
        //Otherwise the content would move too far up when we scroll down.
        //Remove the subraction to see for yourself!
        var targetY:Number = -((CONTENT_HEIGHT - MASK_HEIGHT) * percentage) + myMask.y;
 
        //We only want to animate the scroll if the old y is different from the new y.
        //In our movie we animate the scroll if the difference is bigger than 5 pixels.
        if (Math.abs(oldY - targetY) > 5) {
 
            //Tween the content to the new location.
            //Call the function tweenFinished() when the tween is complete.
            TweenMax.to(myContent, 0.3, {y: targetY, blurFilter:{blurX:22, blurY:22}, onComplete: tweenFinished});
        }
    }
}
 
//This function is called when the tween is finished
function tweenFinished():void {
 
    //Tween the content back to "normal" (= remove blur)
    TweenMax.to(myContent, 0.3, {blurFilter:{blurX:0, blurY:0}});
}

J'ai trouvé ce code sur un site internet... je ne me souviens plus où.... :s
J'ai dans ma bibliothèque 3 clips.... myContent, myMask et scrollMC.

Voila, si vous pouviez m'aider, cela me soulagerait énormément...
Merci d'avance !!

8 réponses

on_drag_on Messages postés 1236 Date d'inscription vendredi 13 mai 2005 Statut Membre Dernière intervention 6 octobre 2010
19 avril 2009 à 09:53
Salut,

Et quel est le problème, qu'est-ce que tu ne comprend pas ?

@+.
telov.ch
0
Artscene Messages postés 5 Date d'inscription dimanche 22 mars 2009 Statut Membre Dernière intervention 19 avril 2009
19 avril 2009 à 12:56
Et bien le soucis, c'est que Flash CS4 me trouve  des erreurs, alors que je n'en vois pas, tout simplement... C'est une erreur 1061 principalement, sur le startDrag et le stopDrag...
Merci d'avance on_drag_on.
0
on_drag_on Messages postés 1236 Date d'inscription vendredi 13 mai 2005 Statut Membre Dernière intervention 6 octobre 2010
19 avril 2009 à 13:20
Et que dit cette erreur ? J'ai testé ton code et il fonctionne parfaitement...
Tu as bien la classe TweenMax dans tes classes ?

@+.
telov.ch
0
Artscene Messages postés 5 Date d'inscription dimanche 22 mars 2009 Statut Membre Dernière intervention 19 avril 2009
19 avril 2009 à 13:52
oui oui j'ai tweenmax, ce n'est plus un problème. La première des 14 erreurs est :
"1061 : Appel à la méthode startDrag ne peut-être non définie via la référence de type static class".
Ensuite j'ai la même pour mon stopDrag...

Encore merci beaucoup ! :)
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
on_drag_on Messages postés 1236 Date d'inscription vendredi 13 mai 2005 Statut Membre Dernière intervention 6 octobre 2010
19 avril 2009 à 14:16
Ton problème ne vient pas du code ...
http://www.telov.ch/scroll.fla

@+.
telov.ch
0
Artscene Messages postés 5 Date d'inscription dimanche 22 mars 2009 Statut Membre Dernière intervention 19 avril 2009
19 avril 2009 à 14:31
Merci, le tien fonctionne parfaitement... Le problème vient d'où d'après toi... Je n'arrive pas à comprendre...

En tout cas,merci beaucoup beaucoup beaucoup !!!!!!
:))

@+
0
on_drag_on Messages postés 1236 Date d'inscription vendredi 13 mai 2005 Statut Membre Dernière intervention 6 octobre 2010
19 avril 2009 à 14:34
Ben c'est à toi de me le dire j'ai simplement repris ton code ... peut-être une erreur dans les noms d'occurrences ... ?

@+.
telov.ch
0
Artscene Messages postés 5 Date d'inscription dimanche 22 mars 2009 Statut Membre Dernière intervention 19 avril 2009
19 avril 2009 à 15:22
C'est exactement cela... Merci pour tout !!!!
Ca fait plaisir une fois que tout fonctionne
Ca soulage !!
0
Rejoignez-nous