Visualizzazione dei risultati da 1 a 3 su 3

Discussione: problema di variabili

  1. #1
    Utente di HTML.it L'avatar di nestore
    Registrato dal
    Feb 2002
    Messaggi
    458

    problema di variabili

    guardate questo codice....mi genera un diagramma a torta...ma se faccio caricare le varibili col loadmovie non mi fa + la torta ma solo un minuscolo spicchio sovrapposto....chi mi da una mano? ecco il codice:



    ci sono le 2 versioni( quella col loadvariables ke non va e quella con gli array tradizionali tra commenti)
    chi mi puo dare 1 mano a capire dove sbaglio? NB: basta copiare il codice sul primo frame e il filmato è fatto.




    stop();
    loadVariables("testo.txt","_level0");
    amounts = new Array; wedgename = new Array;
    // This script was created by Ian Ring, 2002
    // I don't care if you modify or use it in any way
    //
    // this script needs one symbol - the "wedgelabel" -
    // you'll find it in the library. Note that it
    // is linked/exported for Actionscript in the 1st frame

    _level0.onData = function (){
    // create the array of data
    // these are data amounts, not percentages, so
    // they do not have to add up to 100

    amounts = valori.split(",");
    wedgename = nomi.split(",");
    /*
    amounts[0] = 10; wedgename[0] = "always"
    amounts[1] = 20; wedgename[1] = "never"
    amounts[2] = 30; wedgename[2] = "sometimes"
    amounts[3] = 40; wedgename[3] = "yes"
    amounts[4] = 15; wedgename[4] = "no"
    amounts[5] = 65; wedgename[5] = "often"
    amounts[6] = 20; wedgename[6] = "rarely"
    amounts[7] = 65; wedgename[7] = "undecided"
    */

    // array of colours
    colours = new Array;
    colours[0]="0xff0000";colours[1]="0x00ff00";colours[2]="0x0000ff"
    colours[3]="0xffff00";colours[4]="0x00ffff";colours[5]="0xff00ff"
    colours[6]="0x990000";colours[7]="0x009900";colours[8]="0x000099"
    colours[9]="0x999900";colours[10]="0x009999";colours[11]="0x990099"


    // set your parameters
    var extrudelabels=true // if this is true, the script will pull labels out of smaller wedges with a line
    var radius=100 // circle radius
    var labelradius= radius * .8 // this is overridden later on if extrudelabels is true. Otherwise you'll want to set it here.
    var roundplaces = 1 // number of decimal points in the wedge label
    var centerpointx=200 // x of center of circle
    var centerpointy=200 // y of center of circle
    var linewidth=2
    var outlinecolour = "0x000000"
    var minwedgesize = 40 // in degrees, the size of a wedge big enough for the label to go inside
    var angleoffset=90 // by default, the pie begins in the east. This offset rotates the whole pie, in degrees, CCW. A value of 90 starts the pie at "north"



    // warning: unless you are pretty familiar with scripting, don't edit anything below here





    // initialize vars
    var fromangle=0
    var toangle=0
    var totalamount=0
    // get total
    for (zz=0;zz<=amounts.length;zz++){
    totalamount = totalamount + amounts[zz]
    }
    fromangle=0
    // loop through array
    for (z=0;z<amounts.length;z++){
    toangle = fromangle + ((amounts[z]/totalamount)*360)
    // create a new clip
    _root.createEmptyMovieClip ("wedge" add z, 1);
    with (_root.wedge add z){
    // draw into the clip
    beginFill (colours[z%colours.length], 100); // fill colour, alpha
    lineStyle (linewidth, outlinecolour, 100); // line width, colour, and transparency
    moveTo (centerpointx, centerpointy);
    for (i=fromangle-(angleoffset+1);i<toangle-angleoffset;i++){
    lineTo (radius*Math.cos(Math.PI/180 * i)+centerpointx, radius*Math.sin(Math.PI/180 * i)+centerpointy);
    }
    endFill();
    }

    // draw label
    _root.attachmovie("wedgelabel","wedgelabel"+z, z+10)
    thingname = eval("wedgelabel"+z)
    thingname.labeltext = roundme((amounts[z]/totalamount)*100,roundplaces) + "%";
    thingname.wedgename = wedgename[z]
    var bisect = fromangle + ((toangle-fromangle)/2) -angleoffset // bisecting angle of wedge

    // this code adds some aesthetic placement to the labels
    if (extrudelabels){
    if (((amounts[z]/totalamount)*360)>minwedgesize){ // it's a big slice
    labelradius = radius *.6 // put the label inside the slice
    }else{
    labelradius = radius *1.3 // put it outside the slice
    // draw a line pointing to the wedge
    _root.createEmptyMovieClip ("line" add z, z+30);
    with (_root.line add z){
    // draw into the clip
    beginFill (0xffffff, 0); // fill colour, alpha
    lineStyle (1, 0x000000, 100); // line width, colour, and transparency
    moveTo (radius*.7*Math.cos(Math.PI/180 * bisect)+centerpointx,radius*.7*Math.sin(Math.PI/180 * bisect)+centerpointy);
    lineTo (radius*1.1*Math.cos(Math.PI/180 * bisect)+centerpointx, radius*1.1*Math.sin(Math.PI/180 * bisect)+centerpointy);
    endFill();
    }
    }
    }
    thingname._x = labelradius * Math.cos(Math.PI/180 * bisect)+centerpointx
    thingname._y = labelradius * Math.sin(Math.PI/180 * bisect)+centerpointy
    fromangle=toangle
    }
    function roundme(num, places){
    return Math.round(num * (Math.pow(10,places)))/(Math.pow(10,places))
    }
    function normalize (x, y) {
    x = x%y;
    if (x<0) {
    x = y+x;
    }
    return x;
    }
    }

  2. #2
    Utente di HTML.it L'avatar di nestore
    Registrato dal
    Feb 2002
    Messaggi
    458
    dimenticavo: il file testo.txt ha questo contenuto:



    valori=10,20,30,40,15,65,20,65&nomi=always,never,s ometimes,yes,no,often,rarely,undecided

  3. #3
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    codice:
    stop();
    dati = new LoadVars();
    dati.onLoad = function(success)
    {
    	if(success){
    		amounts = new Array(); wedgename = new Array(); 
    		amounts = dati.valori.split(",");
    		wedgename = dati.nomi.split(","); 
    		/* 
    		amounts[0] = 10; wedgename[0] = "always" 
    		amounts[1] = 20; wedgename[1] = "never" 
    		amounts[2] = 30; wedgename[2] = "sometimes" 
    		amounts[3] = 40; wedgename[3] = "yes" 
    		amounts[4] = 15; wedgename[4] = "no" 
    		amounts[5] = 65; wedgename[5] = "often" 
    		amounts[6] = 20; wedgename[6] = "rarely" 
    		amounts[7] = 65; wedgename[7] = "undecided" 
    		*/ 
    		
    		// array of colours 
    		colours = new Array(); 
    		colours[0]="0xff0000";colours[1]="0x00ff00";colours[2]="0x0000ff" 
    		colours[3]="0xffff00";colours[4]="0x00ffff";colours[5]="0xff00ff" 
    		colours[6]="0x990000";colours[7]="0x009900";colours[8]="0x000099" 
    		colours[9]="0x999900";colours[10]="0x009999";colours[11]="0x990099" 
    		
    		
    		// set your parameters 
    		extrudelabels=true 
    		radius=100 // circle radius 
    		labelradius= radius * .8
    		roundplaces = 1 // number of decimal points in the wedge label 
    		centerpointx=200 // x of center of circle 
    		centerpointy=200 // y of center of circle 
    		linewidth=2 
    		outlinecolour = "0x000000" 
    		minwedgesize = 40
    		angleoffset=90
    	} 
    };
    
    dati.load("testo.txt");

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.