Fonction qui fait ramer ma machine

Résolu
mikouRoux Messages postés 69 Date d'inscription jeudi 16 novembre 2006 Statut Membre Dernière intervention 6 octobre 2009 - 18 juil. 2007 à 16:39
mikouRoux Messages postés 69 Date d'inscription jeudi 16 novembre 2006 Statut Membre Dernière intervention 6 octobre 2009 - 19 juil. 2007 à 16:50
Salut à tous,

Merci beaucoup pour votre aide ces dernier jours. Sans vous je ne serais jamais parvenu à faire mon petit programme.

A présent, tout commence à fonctionner comme je veux. Il ne reste qu'un seul souci, ma dernière foonction fait méchemment ramer mon PC

Cette fonction permet d'afficher aléatoirement des lignes qui apparaissent et disparaissent avec fondu entre des movieClip disposés sur ma page.

Je pense que l'erreur est lié au fait que je ne supprime jamais les fonctions chargées. Du coup, ca stock ca stock ca stock. Et au final, l'animation n'est plus fluide du tout.

Si quelqu'un pouvait m'expliquer comment résoudre ce problème ce serait génial.
Ci dessous le code (avec en rouge et à la fin la fonction qui plombe tout) :

// XML
var xml:XML =new XML();
xml.ignoreWhite=true;
xml.load("pctdata.xml");
stop();
xml.onLoad=function(){
    traceWire();
    trace(this.firstChild.childNodes[1-1].attributes.image);
    viewer_mc._visible=false;
    _global.fActiv=false;
    slide();
    play();
}
// focus on red dots
function onEnterFrame(){
    for(i=1; i<=16; i++){
        light(focus_mc=this['dot'+i+'_mc']);
        this['dot'+i+'_mc'].onPress = function(){
            var num = this._name.substring(3, this._name.length-3);
            _global.fTarget=(this._name);
            fleche(_global.fTarget);
            viewer_mc._visible = true;
            loadMovie(xml.firstChild.childNodes[num].attributes.image , _root.viewer_mc.roomPicture_mc)
        }
    }
}
function light(){
    dx = (focus_mc._x-_xmouse);
    dy = (focus_mc._y-_ymouse);
    focus_mc._alpha = Math.sqrt(dx*dx+dy*dy);
    focus_mc._height = 30*(200-focus_mc._alpha)/300;
    focus_mc._width = 30*(200-focus_mc._alpha)/300;
    focus_mc._alpha = 100*(200-focus_mc._alpha)/200;
    if (focus_mc._width<6){
        focus_mc._width=6;
        focus_mc._height=6;
    }
}
container_mc.onMouseMove = function(){
    resizeViewer();
}
function resizeViewer(){
        viewer_mc.roomMask_mc._width=_xmouse;
        viewer_mc.roomMask_mc._height=_ymouse;
        viewer_mc.roomMask_mc._x=0;
        viewer_mc.roomMask_mc._y=0;
        viewer_mc.roomPicture_mc._x=0;
        viewer_mc.roomPicture_mc._y=0;
        if (_xmouse>_ymouse*1.33){
            viewer_mc.roomPicture_mc._width=_xmouse;
            viewer_mc.roomPicture_mc._height=viewer_mc.roomPicture_mc._width/1.33;
        }else if(_xmouse<_ymouse*1.33){
            viewer_mc.roomPicture_mc._height=_ymouse;
            viewer_mc.roomPicture_mc._width=viewer_mc.roomPicture_mc._height*1.33;
        }
}
container_mc.onPress = function(){
    viewer_mc._visible = false;
    _root.line_mc.removeMovieClip();
}
function fleche(id){
    var posX = getProperty(id, _x)
    var posY = getProperty(id, _y)
    this.createEmptyMovieClip("line_mc", 1);
    line_mc.lineStyle(1, 0xff00ff, 100);
    line_mc.moveTo(_xmouse, _ymouse);
    line_mc.lineTo(posX, posY);
}
dureeAffichage = setInterval(function(){randomWire();}, 5000);

//////////////////////////////////////////////////////////////////////////////////////

/* FONCTION QUI FAIT RAMER MA MACHINE

--------------------------------------
function traceWire(){
    trace('wire');
    dotA = this['dot'+random(17)+'_mc'];
    dotB = this['dot'+random(17)+'_mc'];
    trace(dotA+" "+dotB);
    this.createEmptyMovieClip("randomLine_mc", 1);
    randomLine_mc.lineStyle(2, 0xffffff, 100);
    randomLine_mc.moveTo(dotA._x, dotA._y);
    randomLine_mc.lineTo(dotB._x, dotB._y);
    var opacity:Number=0;
    var flag:Number=0;
    setInterval(function(){fade()},10);
    function fade(){
        _root.randomLine_mc._alpha=opacity;
        if (flag==0){fadeIn()}
        if(flag==100){fadeOut()}
        function fadeIn(){
            trace(opacity);
            if(opacity>99){flag=100;}
            else {opacity++;}
        }
        function fadeOut(){
            trace(opacity);
            if(opacity<1){flag=0;}
            else {opacity--;}
            if (opacity<1){traceWire();};
        }
    }
}

1 réponse

mikouRoux Messages postés 69 Date d'inscription jeudi 16 novembre 2006 Statut Membre Dernière intervention 6 octobre 2009
19 juil. 2007 à 16:50
C bon, j'ai trouvé la solution :

function traceWire(){
    dotA = this['dot'+random(17)+'_mc'];
    dotB = this['dot'+random(17)+'_mc'];
    trace("dotA : "+dotA+" dotB : "+dotB);
    this.createEmptyMovieClip("randomLine_mc", 1);
    randomLine_mc.lineStyle(2, 0xffffff, 100);
    randomLine_mc.moveTo(dotA._x, dotA._y);
    randomLine_mc.lineTo(dotB._x, dotB._y);
    var opacity:Number=0;
    var flag:Number=0;
    fadeInterval = setInterval(function(){fade()},10);
    function fade(){
        _root.randomLine_mc._alpha=opacity;
        if (flag==0){fadeIn()}
        if(flag==100){fadeOut()}
        function fadeIn(){
            if(opacity>99){flag=100;}
            else {opacity++;}
        }
        function fadeOut(){
            if(opacity<1){flag=0;}
            else {opacity--;}
            if (opacity<1){clearInterval(fadeInterval); traceWire();};
        }
    }
3
Rejoignez-nous