2013-03-30 2 views
1

예를 들어 .appendText() 및 array.push와 함께 예기치 않은 결과가있는 GeolocationEvent.UPDATE 예제를보고 actionscript를 처음 보았습니다. 둘 다 전화가 업데이트를 따라갈 수 있는지 여부를 알지 못합니다..appendText는 GeolocationEvent.UPDATE에서 대체하지 않고 마지막 텍스트 위에 쓰고 있습니다.

먼저 텍스트 쓰기 문제는 마지막 쓰기를 덮어 쓰지 않고 덮어 쓰는 것입니다. 전화에서 몇 분 정도 앱을 실행 한 후에는 더 이상 숫자를 읽을 수 없습니다. - this.removeChild()를 사용한 다음 addChild()가 마지막 쓰기를 제거하기 전에 다시 쓰기를 시도하는 것에 관한 것입니다.

두 번째로 배열의 문제는 trace()에서 임의의 .length 숫자를 출력한다는 것입니다. 길이가 다시 계산되기 전에 2로 재설정되는 것처럼 보입니다. 그리고 무작위로 보이는 숫자까지 계산됩니다. 나는 최종 버전에서 배열의 오버 헤드를 원하지 않는다는 것을 알고 있지만 왜 작동하지 않는지 알기 위해 노력하고 있습니다.

내가

var format:TextFormat = new TextFormat(); 
    format.color = 0xff0066; 
    format.font = "Lucida Console"; 
    format.size = 20; 
var fl_GeolocationDisplay:TextField = new TextField(); 
    fl_GeolocationDisplay.defaultTextFormat = format; 
    fl_GeolocationDisplay.x = 10; 
    fl_GeolocationDisplay.y = 20; 
    fl_GeolocationDisplay.selectable = false; 
    fl_GeolocationDisplay.autoSize = TextFieldAutoSize.LEFT; 
//fl_GeolocationDisplay.text = "Geolocation is not responding. Verify the device's  location settings."; 
fl_GeolocationDisplay.text = " "; 
addChild(fl_GeolocationDisplay); 

var gpsArray:Array = [42.09646417]; 

if(!Geolocation.isSupported) 
{ 
    fl_GeolocationDisplay.text = "Geolocation is not supported on this device."; 
} 
else 
{ 
    var fl_Geolocation:Geolocation = new Geolocation(); 
    fl_Geolocation.setRequestedUpdateInterval(60000); //android overrides  setRequestedUpdateInterval() 
    fl_Geolocation.addEventListener(GeolocationEvent.UPDATE, fl_UpdateGeolocation); 
    fl_Geolocation.addEventListener(StatusEvent.STATUS, gpsStatusHandler); 
} 

function fl_UpdateGeolocation(event:GeolocationEvent):void 
{ 
    //gpsArray.push(event.latitude); 
    //gpsArray[gpsArray.length] = event.latitude; 
    gpsArray.unshift(event.latitude); 
    var speed:Number = event.speed * 2.23693629; 
    if (gpsArray[gpsArray.length - 2] != gpsArray[gpsArray.length - 1]) 
    {  
     trace(gpsArray.length + "|" + gpsArray[gpsArray.length - 2] + "|" +  gpsArray[gpsArray.length - 1]); 
     trace(gpsArray[1] + "|" + gpsArray[0]); 
     trace(gpsArray[gpsArray.length - 2] - gpsArray[gpsArray.length - 1]); 
    } 

    //this.removeChild(fl_GeolocationDisplay); 
    fl_GeolocationDisplay.parent.removeChild(fl_GeolocationDisplay); 
    //fl_GeolocationDisplay = null; //TypeError: Error #2007: Parameter child must be non-null. 
    addChild(fl_GeolocationDisplay); 
    fl_GeolocationDisplay.text = (event.latitude.toString() + " | " +  event.timestamp.toString()); 
    //fl_GeolocationDisplay.text = (event.latitude.toString() + "\n"); 
    //fl_GeolocationDisplay.appendText(event.latitude.toString() + "\n"); 
    //fl_GeolocationDisplay.appendText(event.longitude.toString() + "\n"); 
} 

function gpsStatusHandler(event:StatusEvent):void { 
    if (fl_Geolocation.muted) { 
     fl_GeolocationDisplay.text = "Please verify the device's location  settings."; 
    } 
} 
+0

단락에서 텍스트 벽을 다시 포맷 할 수 있습니까? 그것은 당신의 문제를 읽고 포착하기가 어렵 기 때문입니다. –

+0

감사합니다. - 내가 더 명확하게 만들었습니다. – user2224471

답변

0

내가 정말 당신이하려고하는 것이 무엇인지 이해할 수없는 여기에 기본적인 뭔가를 놓친 적이 있다면 난 - 미안 시도한 다른 일을 주석 처리했습니다 내 말은 당신이 한 가지 말을하지만 코드가 다른 것을 말하는 것입니다.

다른 코드 스 니펫이있는 위치에 대한 심각한 문제가 있습니까? 그것은 상단 부분이 생성자 내부에있는 것처럼 보입니다. 그리고 나서 바닥 부분은 그들 자신의 기능입니까? 그렇다면 생성자가 여러 번 실행되지 않는지 확인하십시오 (문제 인 것 같고 항목이 서로 위에 "덮어 쓰여진 이유"를 설명하는 것 같습니다.)

또한 appendText에 대한 내용이 있지만 당신이 텍스트 필드 안의 텍스트를 바꾸고 싶어하는 것 같습니까? AppendText는 텍스트 필드 안에 여분의 텍스트를 추가합니다.

어쨌든, 나는 업데이트 이벤트에서 "경도 | 위도"를 얻은 다음 코드를 추가했습니다. 이 새로운 라인의 텍스트 필드에. 아마도 당신이 원했던 것일 수도 있습니다. 나는 이것을 수행함으로써 당신이 달성하려고 시도한 것이 무엇인지 전혀 몰랐기 때문에 GPS 어레이를 주석 처리했습니다 :

package { 
    import flash.events.GeolocationEvent; 
    import flash.events.StatusEvent; 
    import flash.sensors.Geolocation; 
    import flash.text.TextField; 
    import flash.text.TextFieldAutoSize; 
    import flash.text.TextFormat; 


    public class Foobar extends MovieClip { 
     var gpsArray:Array = [42.09646417]; 
     var format:TextFormat = new TextFormat(); 
     var fl_GeolocationDisplay:TextField = new TextField(); 
     var fl_Geolocation:Geolocation = new Geolocation(); 

     public function Foobar() { 
      format.color = 0xff0066; 
      format.font = "Lucida Console"; 
      format.size = 20; 
      fl_GeolocationDisplay.defaultTextFormat = format; 
      fl_GeolocationDisplay.x = 10; 
      fl_GeolocationDisplay.y = 20; 
      fl_GeolocationDisplay.selectable = false; 
      fl_GeolocationDisplay.autoSize = TextFieldAutoSize.LEFT; 
      //fl_GeolocationDisplay.text = "Geolocation is not responding. Verify the device's  location settings."; 
      fl_GeolocationDisplay.text = " "; 
      addChild(fl_GeolocationDisplay); 


      if(!Geolocation.isSupported) { 
       trace("unsupported"); 
       fl_GeolocationDisplay.text = "Geolocation is not supported on this device."; 
      } else { 
       trace("supported"); 
       fl_Geolocation.setRequestedUpdateInterval(500); //android overrides  setRequestedUpdateInterval() 
       fl_Geolocation.addEventListener(GeolocationEvent.UPDATE, fl_UpdateGeolocation); 
       fl_Geolocation.addEventListener(StatusEvent.STATUS, gpsStatusHandler); 
      } 
     } 

     function fl_UpdateGeolocation(event:GeolocationEvent):void { 
      /*gpsArray.unshift(event.latitude); 
      var speed:Number = event.speed * 2.23693629; 
      if (gpsArray[gpsArray.length - 2] != gpsArray[gpsArray.length - 1]) { 
       trace(gpsArray.length + "|" + gpsArray[gpsArray.length - 2] + "|" +  gpsArray[gpsArray.length - 1]); 
       trace(gpsArray[1] + "|" + gpsArray[0]); 
       trace(gpsArray[gpsArray.length - 2] - gpsArray[gpsArray.length - 1]); 
      }*/ 

      fl_GeolocationDisplay.appendText(event.latitude.toString() + "|" + event.longitude.toString() + "\n"); 
     } 

     function gpsStatusHandler(event:StatusEvent):void { 
      if (fl_Geolocation.muted) { 
       fl_GeolocationDisplay.text = "Please verify the device's location  settings."; 
      } 
     } 
    } 

} 
+1

당신은 절대적으로 옳았습니다. 여러 번 호출되었으므로 배열 문제도 해결했습니다. 죄송합니다. 덕분에 너무 많이 – user2224471

+0

다행히 도울 수있어 :) –

관련 문제