Petit coup de main sur un action script

pdavid1985 Messages postés 5 Date d'inscription lundi 9 mars 2009 Statut Membre Dernière intervention 23 juin 2009 - 23 juin 2009 à 10:42
latour500 Messages postés 63 Date d'inscription dimanche 5 novembre 2000 Statut Membre Dernière intervention 10 décembre 2009 - 23 juin 2009 à 18:16
Bonjour,

Voila j'ai trouvé un code sur ce site qui vise à créer une bannière flash pour afficher des images défilantes et qui fait appel pour ça à un xml.
Ce fla correspond exactement à ce que je veux faire pour mon site à une exception près :
je voudrais que la bannière créée soit verticale et non pas horizontale.

Je joins l'action script utilisé :
import Main2;

var xmlloader:XmlLoader = new XmlLoader("imgs.xml");
var xml:XML = new XML();

xmlloader.addEventListener(XmlLoader.XmlLoader_Finish, xmlLoadComplete);
function xmlLoadComplete(evt:Event):void {
    xml = xmlloader.getXMLData();
    xmlloader.dispose();
    var nbimage:int;
    var lstImgs:XMLList;
    nbimage = xml.icon.length();
    //trace(nbimage);
    lstImgs = xml.icon;

    var countimg:int = 0;
    var tmpcount:int = 0;
    var imgs:Array = new Array();

    for each (var imgxml:XML in lstImgs) {
        tmpcount +=1;
        if (tmpcount <8) {
            var img1:Main2 = new Main2(imgxml.@image,imgxml.@action,imgxml.@titre);
            img1.x = (countimg * 100)+(countimg*5);
            imgs[tmpcount] = img1;
            addChild(imgs[tmpcount]);
            imgs[tmpcount].GoNext();
            countimg += 1;
        } else {
            imgs[tmpcount - 7].Add(imgxml.@image,imgxml.@action,imgxml.@titre);
        }
        //trace(imgxml.@action + " " + imgxml.@titre);

    }

}
_________________________________________________________________________________________

a savoir qu'il y a en plus un fichier nommé "main2.as" qui ressemble à ça :

package {
    import flash.display.Sprite;
    import flash.net.URLRequest;
    import flash.display.Loader;
    import flash.display.Bitmap;
    import flash.events.Event;
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import flash.utils.Timer;
    import fl.transitions.TweenEvent;
    import flash.events.TimerEvent;
    import flash.events.MouseEvent;
    import flash.net.navigateToURL;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;

    public class Main2 extends Sprite {
        private var ldr:Loader;
        private var bmp:Bitmap;
        private var twn:Tween;
        private var tmr:Timer = new Timer(5500,1);
        private var obj: Object = new Object();
        private var url:String;
        private var desc:String;
        private var label:TextField;

        private var urls:Array = new Array();
        private var urlsImages:Array = new Array();
        private var descs:Array = new Array();
        private var bmps:Array = new Array();

        public function Main2(urlImage:String,urldestination:String,description:String):void {
            Add(urlImage,urldestination,description);
        }
        public function Add(urlImage:String,urldestination:String,description:String):void {
            var idx:int = urlsImages.length;
            if (idx == 0) {
                idx=1;
            }
            urlsImages[idx] = urlImage;
            urls[idx] = urldestination;
            descs[idx] = description;
        }
        var currentIdx:int=1;

        public function GoNext():void {
            if (bmp!=null) {
                //trace("REMOVE BMP");
                removeChild(bmp);
            }
            if (label!=null) {
                //trace("REMOVE LABEL");
                removeChild(label);
            }
            bmp = null;
            ldr = null;
            label=null;

            if (currentIdx<(urlsImages.length)) {
                Launch(urlsImages[currentIdx],urls[currentIdx],descs[currentIdx],currentIdx);
                currentIdx +=1;
            } else {
                currentIdx = 1;
                GoNext();
            }
        }
        var idxBmp:int = 0;
        public function Launch(urlImage:String,urldestination:String,description:String,idx:int):void {
            url = urldestination;
            desc=description;
            bmp = new Bitmap();
            if (bmps[idx] ==  null) {
                idxBmp = idx;
                ldr = new Loader();
                ldr.load(new URLRequest(urlImage));
                ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,LoadComplete);
            } else {
                LoadFromArray(idx);
            }
            this.buttonMode = true;
            this.useHandCursor = true;
        }
        private function LoadComplete(evt:Event):void {
            bmp = Bitmap(ldr.content);
            bmps[idxBmp] = bmp;
            //trace("bmp en mémoire");
            bmp.y=-180;
            bmp.smoothing = true;
            //ResizeImage.resizeIt(bmp,100,100);
            bmp.height=80;
            bmp.width=100;
            anim();
            addChild(bmp);
            tmr.addEventListener(TimerEvent.TIMER, onMyTimer);
            BuildLabel();
        }
        private function LoadFromArray(idx:int):void {
            bmp = Bitmap(bmps[idx]);
            bmp.smoothing = true;
            //ResizeImage.resizeIt(bmp,100,100);
            bmp.height=80;
            bmp.width=100;
            anim();
            addChild(bmp);
            tmr.addEventListener(TimerEvent.TIMER, onMyTimer);
            BuildLabel();
        }
        private function BuildLabel():void {
            label = new TextField();
            label.y=-180;//75
            label.multiline=true;
            label.htmlText="" + desc + "";
            //label.autoSize=TextFieldAutoSize.CENTER;
            var format:TextFormat = new TextFormat();
            format.font = "Verdana";
            format.color = "0x0000FF";
            format.size = 8;
            format.underline = true;
            format.url = url;
            format.target="_blank";
            label.defaultTextFormat = format;
            addChild(label);
        }
        public function anim():void {
            //twn = new Tween(bmp,"y",Regular.easeInOut,-90,0,.5,true);
            twn = new Tween(obj,"propcount",Bounce.easeInOut,-1,0,1,true);
            //twn = new Tween(obj,"propcount",Bounce.easeInOut,-1,0,.5,true);
            twn.addEventListener(TweenEvent.MOTION_CHANGE,tweenIn);
            twn.addEventListener(TweenEvent.MOTION_FINISH,tweenOut);
            addEventListener(MouseEvent.CLICK,ImageClick);
            //tmr.start();
        }
        public function ImageClick(evt:MouseEvent):void {
            navigateToURL(new URLRequest(url),"_blank");
        }
        public function tweenIn(evt:TweenEvent):void {
            bmp.y = 180*obj.propcount;
            //bmp.alpha = (obj.propcount)+1;
            label.y = bmp.y+75;
            //label.alpha = (obj.propcount)+1;
            //bmp.scaleX = obj.propcount * -1;
            //bmp.scaleY = obj.propcount * 1;
        }
        public function tweenOut(evt:TweenEvent):void {
            tmr.start();
        }
        public function tweenOutEnd(evt:TweenEvent):void {
            GoNext();
        }
        function onMyTimer(evt:TimerEvent):void {
            twn = new Tween(bmp,"y",Bounce.easeInOut,0,180,.5,true);
            twn = new Tween(label,"y",Bounce.easeInOut,75,180,.5,true);
            twn.addEventListener(TweenEvent.MOTION_FINISH,tweenOutEnd);
        }
    }
}
import flash.display.Sprite;
class testclass {

}

_________________________________________________________________________________________

Voila, je me lance tout juste dans Flash et ses mystères. Ce que je vous demande ce n'est pas forcement de faire mon boulot à ma place mais juste d'essayer de m'indiquer quel bout de code correspond au position des diverses images.
Histoire que je puisse les replacer de façon verticale.

Merci beaucoup d'avance...

1 réponse

latour500 Messages postés 63 Date d'inscription dimanche 5 novembre 2000 Statut Membre Dernière intervention 10 décembre 2009
23 juin 2009 à 18:16
Bonjour,

regarde ici  peut être ---> 

private function LoadComplete(evt:Event):void {
            bmp = Bitmap(ldr.content);
            bmps[idxBmp] = bmp;
            //trace("bmp en mémoire");
            bmp.y=-180;
            bmp.smoothing = true;
            //ResizeImage.resizeIt(bmp,100,100);
            bmp.height=80;
            bmp.width=100;
            anim();
            addChild(bmp);
            tmr.addEventListener(TimerEvent.TIMER, onMyTimer);
            BuildLabel();
        }
        private function LoadFromArray(idx:int):void {
            bmp = Bitmap(bmps[idx]);
            bmp.smoothing = true;
            //ResizeImage.resizeIt(bmp,100,100);
            bmp.height=80;
            bmp.width=100;
            anim();
            addChild(bmp);
            tmr.addEventListener(TimerEvent.TIMER, onMyTimer);
            BuildLabel();
        }
bon courage
0
Rejoignez-nous