0

配列とビット演算子の処理に問題があります...

それが問題です:私はCheckBoxとして入力された配列を持っています、この配列には3つのチェックボックスがあります。1つはオプション(pvrtc、dtc1、dtx15)ごとにあり、次にオプションがあります。ここで、状態にビット演算子を使用したいと思います。

それは私が今まで得たものです:

// thats my class with the possible states like consts
public class CompressionCombinations {

public static const selectedPvrtc:uint = 1<<0;

public static const selectedEtc1:uint = 1<<1;

public static const selectedDxt15:uint = 1<<2;

public static const selectedPvrtcEtc1Dxt15:uint = selectedPvrtc && selectedEtc1 && 
selectedDxt15;
// thats mean: selectedPvrtc = checkbox1 true, checkbox2 false, checkbox3 false.

//now my main class

//attributing my checkboxes into array

_combinationArray = new Array();
_combinationArray[0] = _checkBoxPvrtc;
_combinationArray[1] = _checkBoxEtc1;
_combinationArray[2] = _checkBoxDxt15;

// a function that do the maths

if((bin=uint(_combinationArray[0].selected + _combinationArray[1].selected +
_combinationArray[2].selected)) == CompressionCombinations.selectedPvrtc){

_argNativeProcess = new String("p");
_nativeProcess.setupAndLaunch(_inputNativeProcess, _outputNativeProcess,  
_argNativeProcess, this);
_msgSuccessErrorTextField.text = "Converting...";
}
else{
trace("not working");
}

それが問題です。ビット演算を適用できません...それを行うための関数の使用方法や作成方法がわかりません。私はビット演算子なしでそれを行う方法を知っていますが、将来の新しいリリースのためにビット演算を使用したいです...

何か案は ?それを解決する方法の提案?

4

1 に答える 1

1
var selectedPvrtc:uint = 1;
var selectedEtc1:uint = 2;
var selectedDxt15:uint = 4;

var _combinationArray :Array = new Array();
_combinationArray [0] = checkBoxPvrtc;
_combinationArray [1] = checkBoxEtc1;
_combinationArray [2] = checkBoxDxt15;
var tmp:uint = 0;
for(var i:int = 0;i<_combinationArray.length;i++){
    tmp = tmp|(uint(_combinationArray[i].selected)<<i);
}

if( tmp & selectedPvrtc){
    trace('selectedPvrtc')
}
if( tmp & selectedEtc1){
    trace('selectedEtc1')
}
if( tmp & selectedDxt15){
    trace('selectedDxt15')
}
于 2013-03-12T20:19:19.000 に答える