IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Flash Discussion :

[FLASH 8] Problème classe perso


Sujet :

Flash

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éprouvé Avatar de julien.63
    Profil pro
    balayeur
    Inscrit en
    Décembre 2005
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : balayeur

    Informations forums :
    Inscription : Décembre 2005
    Messages : 1 348
    Par défaut [FLASH 8] Problème classe perso
    Salut,
    j'essaie de créer une classe pour dessiner des clip avec des angles ronds.
    quand je crée un objet je n'ai pas ma figure, ni message d'erreur pour m'orienter.
    Il n'y a qu'une seule méthode avec le constructeur.
    Je ne suis pas très expérimenté en AS2, voyez-vous une grosse bourde de ma part?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
     
    class drawPolygon{	
    	private static var angle:Number;
    	private static var mcW:Number;
    	private static var mcH:Number;
    	private static var xPos:Number;
    	private static var yPos:Number;
    	private static var mc:MovieClip;
    	private static var mcName:String;
    	private static var mcDepth:Number;
     
    	/**********************
    	* cible - movie clip where the polygon will be drawn
    	* n - name of the new clip created
    	* d - depths of the new clip created
    	* w - width of the polygon
    	* h - height of the polygon
    	* a - angle of the round corner
    	* xp - x position of the polygon
    	* yp - y position of the polygon
    	************************/
    	public function drawPolygon(cible:MovieClip,n:String,d:Number,w:Number,h:Number,a:Number,xp:Number,yp:Number){
    		mc = cible;
    		mcName = n;
    		mcDepth = d;
    		mcW = w;
    		mcH = h;
    		angle = a;
    		if ((angle*2) > mcH) var angle = mcH / 2;
    		xPos = xp;
    		yPos = yp;
    		trace(mc +" - "+ mcName +" - "+ mcDepth +" - "+ mcW +" - "+ mcH +" - "+ angle +" - "+ xPos +" - "+ yPos);
    		makePolygon();
    	}
     
    	private function makePolygon():Void{
    		var clip = mc.createEmptyMovieClip(mcName,mcDepth);
    		with(clip){
    			lineStyle( 2, 0x00CCFF, 50 );
    			beginFill( 0xFFCC00 );
    			moveTo(xPos,yPos);
    			curveTo(xPos-angle,yPos,xPos-angle,yPos+angle);
    			lineTo(xPos-angle,mcH+yPos-angle);
    			curveTo(xPos-angle,mcH+yPos,xPos,mcH+yPos);
    			lineTo(xPos+mcW-angle,mcH+yPos);
    			curveTo(xPos+mcW,mcH+yPos,xPos+mcW,mcH+yPos-angle);
    			lineTo(xPos+mcW,yPos+angle);
    			curveTo(xPos+mcW,yPos,xPos+mcW-angle,yPos);
    			endFill();
    		}
    	}
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    var polygon:drawPolygon = new drawPolygon(this,"polygon",this.getNextHighestDepth(),300,100,20,50,50);

  2. #2
    Membre Expert Avatar de Lorenzo77
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    1 472
    Détails du profil
    Informations personnelles :
    Âge : 53
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Mai 2006
    Messages : 1 472
    Par défaut
    rajouter des this. pour TOUS LES MEMBRES de la classe

    ex d'un constructeur d'une de mes classes :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
     
    	/*** ---- Carte() : initialise la classe ----
    	*
    	*
    	* (Void)
    	*/
    	function Carte(){
                    this.ini();
    		// --------------------
    		this.tfCarteRouge = new TextFormat();
    		for(var x in this.obCarteRouge){
    			this.tfCarteRouge[x] = this.obCarteRouge[x];
    		}
    		this.tfCarteNoir = new TextFormat();
    		for(var x in this.obCarteNoir){
    			this.tfCarteNoir[x] = this.obCarteNoir[x];
    		}
    		// --------------------
    		// Tableau des couleurs des cartes rouge
    		this.tbRouge = [this.tbCouleur[0], this.tbCouleur[1]];
     
    		// Tableau des couleurs des cartes noir
    		this.tbNoir = [this.tbCouleur[2], this.tbCouleur[3]];
    	}

  3. #3
    Membre éprouvé Avatar de julien.63
    Profil pro
    balayeur
    Inscrit en
    Décembre 2005
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : balayeur

    Informations forums :
    Inscription : Décembre 2005
    Messages : 1 348
    Par défaut
    salut,
    merci pour ta réponse, ça fonctionne .
    Par contre j'ai également dû tout passer (propriété et méthode) en public au lieu de private ! Pourtant je n'y accédais que par l'intermédiaire de la classe ? Pourquoi doivent-elle être public ?

  4. #4
    Membre Expert Avatar de Lorenzo77
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    1 472
    Détails du profil
    Informations personnelles :
    Âge : 53
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Mai 2006
    Messages : 1 472
    Par défaut
    private fonctionne quand tu les utilises dans la classe qui les declare.

    tu aurais pas oublié un this. devant un nom de méthode ?

  5. #5
    Membre éprouvé Avatar de julien.63
    Profil pro
    balayeur
    Inscrit en
    Décembre 2005
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : balayeur

    Informations forums :
    Inscription : Décembre 2005
    Messages : 1 348
    Par défaut
    tu aurais pas oublié un this.
    euuuh pas un, mais 11...
    en fait dans la méthode qui dessine le polygone, je ne pointais pas le bon objet.
    merci pour ton aide, ça marche !!
    voici le code si ça intéresse quelqu'un :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    /**********************
    * this class draw a four side polygon with rounded corner
    **********************/
     
    class drawPolygon{	
    	private var angle:Number;
    	private var mcW:Number;
    	private var mcH:Number;
    	private var xPos:Number;
    	private var yPos:Number;
    	private var mc:MovieClip;
    	private var mcName:String;
    	private var mcDepth:Number;
     
    	/**********************
    	* cible - movie clip where the polygon will be drawn
    	* n - name of the new clip created
    	* d - depths of the new clip created
    	* w - width of the polygon
    	* h - height of the polygon
    	* a - angle of the round corner
    	* xp - x position of the polygon
    	* yp - y position of the polygon
    	************************/
    	public function drawPolygon(cible:MovieClip,n:String,d:Number,w:Number,h:Number,a:Number,xp:Number,yp:Number){
    		this.mc = cible;
    		this.mcName = n;
    		this.mcDepth = d;
    		this.mcW = w;
    		this.mcH = h;
    		this.angle = a;
    		if ((this.angle*2) > this.mcH) this.angle = this.mcH / 2;
    		this.xPos = xp;
    		this.yPos = yp;
    		this.makePolygon();
    	}
     
    	private function makePolygon():Void{
    		var clip:MovieClip = this.mc.createEmptyMovieClip(this.mcName,this.mcDepth);
    		clip.lineStyle( 2, 0x00CCFF, 50 );
    		clip.beginFill( 0xFFCC00 );
    		clip.moveTo(this.xPos,this.yPos);
    		clip.curveTo(this.xPos-this.angle,this.yPos,this.xPos-this.angle,this.yPos+this.angle);
    		clip.lineTo(this.xPos-this.angle,this.mcH+this.yPos-this.angle);
    		clip.curveTo(this.xPos-this.angle,this.mcH+this.yPos,this.xPos,this.mcH+this.yPos);
    		clip.lineTo(this.xPos+this.mcW-this.angle,this.mcH+this.yPos);
    		clip.curveTo(this.xPos+this.mcW,this.mcH+this.yPos,this.xPos+this.mcW,this.mcH+this.yPos-this.angle);
    		clip.lineTo(this.xPos+this.mcW,this.yPos+this.angle);
    		clip.curveTo(this.xPos+this.mcW,this.yPos,this.xPos+this.mcW-this.angle,this.yPos);
    		clip.endFill();
    	}
    }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [WPF] Problème de binding avec une classe perso
    Par Invité dans le forum Windows Presentation Foundation
    Réponses: 5
    Dernier message: 12/04/2010, 18h45
  2. [AS3] Problème d'import de classes perso.
    Par Toph' dans le forum ActionScript 3
    Réponses: 2
    Dernier message: 30/08/2007, 10h12
  3. Problème classe perso chaine de caractères
    Par stof dans le forum Visual C++
    Réponses: 2
    Dernier message: 06/05/2007, 11h42
  4. Réponses: 3
    Dernier message: 05/12/2006, 13h18
  5. [FLASH MX2004] Problème de classe
    Par JulPoWeR dans le forum Flash
    Réponses: 1
    Dernier message: 10/07/2005, 22h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo