{lang: 'de'}
Flashhilfe.de - Flash Community

Variabler/Dynamischer Instanzname? [Flash 9]

 


AntwortenRegistrieren Seite1  

Tom786#1
Benutzerbild von Tom786
Beiträge: 23
Registriert: Jan 2011

21.01.2011, 02:53

Ich habe mehre MCs im Flash und lese Daten aus einer MS-Access Datenbank aus.
Jetzt soll aber je nach Daten ein anderer MC aktiv sein.
Muss ich da ein switch reinbauen (was etwas gar aufwändig wäre) oder bringe ich untenstehendes Skript auch eleganter zum Laufen?

Problematischer Code:
ActionScript:
1
2
3
4
5
6
         if(currentIcon != ""){
              root[currentIcon].visible = false;
           }//end if
         var currentIcon = currentC;
         currentIcon += "_icon";
         root[currentIcon].visible = true;


Gekürztes Skript von wegen Zusammenhang:
ActionScript:
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//initiate script
stop();

ssCore.init();
ssDefaults.synchronousCommands = true;
ssCore.ADO.setConnectString({connectString:"Provider=Microsoft.Jet.OLEDB.4.0; Persist Security Info=False; Data Source="+ssGlobals.ssStartDir+"dbactdb.mdb;"});
ssCore.ADO.setRowFormat({format: "DLM"});
ssCore.ADO.setDelimiter({delimiter: "t"});
ssCore.ADO.setSeparator({separator: "n"});

a.visible = false;
b.visible = false;
//[...]
a_icon.visible = false;
b_icon.visible = false;
//[...]

//[...]

var currentID = 0;
var currentIcon = "";
//[...]

root.addEventListener(MouseEvent.CLICK, mouseClick);
//[...]

function mouseClick(e:MouseEvent):void{
     //read from actdb.mdb
   ssCore.ADO.setSQL({sql:"select * from [Test] where [ID] = "+(currentID+1)});
     var return_obj = ssCore.ADO.open();
     if (return_obj.success){
        return_obj = ssCore.ADO.getRows();
        if (return_obj.success){
           //split the results
         var   records = return_obj.result.split('n');
           for (var i = 0 ; i < records.length ; i++){
              var fields = records[i].split('t');
           }//end for
         //assign variables to the results (note: fields[0] = [ID])
         var currentC = fields[1];
           var currentE = fields[2];
           var currentTxt = fields[3];
           var currentB = fields[4];
           var currentJ = fields[5];
           var currentCall = fields[6];
           var currentR = fields[7];
           
           //update Textfield
         if(currentTxt != UI.banner.txtfield.text){
              UI.banner.txtfield.text = currentTxt;
           }//end if
         
           //update Icon
         if(currentIcon != ""){
              root[currentIcon].visible = false;
           }//end if
         var currentIcon = currentC;
           currentIcon += "_icon";
           root[currentIcon].visible = true;
           //[...]
         
           currentID++;
           
         }//end if
       else{ //ssCore.ADO.getRows() failed
         ssDebug.trace("ADO.getRows ERROR: "+return_obj.Error.description);
        }//end else
   }//end if
   else{ //ssCore.ADO.open() failed
      ssDebug.trace("ADO.open ERROR: "+return_obj.Error.description);
        ssDebug.trace(" adoError: "+return_obj.adoError);
     }//end else
}//end function
//[...]
//end script


Ps: Habs gerade erst gemerkt, aber das Forum ignoriert alle Backslash. Die "fehlenden" Backslash im setConnectString, setDelimiter, setSeparator und in den split() sind also nicht Teil des Problems.
Geändert von Tom786 am 21.01.11 um 03:30 Uhr
RustyCake#2
Benutzerbild von RustyCake
Beiträge: 1776
Wohnort: Laimbach 6 1/2
Registriert: Nov 2002

21.01.2011, 12:04