5 Replies Latest reply on Oct 29, 2011 11:04 PM by pauland

    Why does this work on droid but not iOS

    alinator11 Level 2

      I have been trying to figure out why my app runs perfectly on Android and yet I can only get the first screen to load on iOS. For more than a day I've banged my head against the wall to no avail and unfortunately my forum question on the matter has garnered no responses. So... instead of the larger, why won't my whole app work, question... how about why won't this code on the first page of my view behave exactly the same on iOS as it does on Android? Anyone? This is killing me... Argggggg. First view loads on iOS but then you can't go anywhere from there:

       


      <s:SWFLoader


      id="splashVidLoader"


      x="0" y="0"


      width="100%" height="100%"


      scaleContent="true"


      source="@Embed('assets/iOSIntro.swf')"


      autoLoad="true"


      creationComplete="{initLoader()}"


      />

       




      private function initLoader():void {




      var t:Timer = new Timer(30000);




      t.start();




      t.addEventListener(TimerEvent.TIMER_COMPLETE, timesUp);




      pm = new PersistenceManager();




      pm.load();







      pm.setProperty("enemyinit", "true");




      pm.save();




      splashVidLoader.content.addEventListener(Event.ADDED, onLoadSWF);






      }

       




      private function timesUp(timerEvent:TimerEvent):void {



             mainMovie.stop();



      }







      private var mainMovie:MovieClip;



      private function onLoadSWF(event:Event):void {



          event.target.removeEventListener(Event.ADDED, onLoadSWF);



          if(event.target.name == "introScreenMain") {



                      mainMovie = MovieClip(event.target);







         }...}

       

       

      On Android, the above code will cause the SWF to load, display, play for 30 seconds and then stop on the last frame. On iOS, the above will cause the SWF to load, display and then loop. Why?

       

       

       

      Here is another example of how iOS and Andriod deployments are not consistent for me...

       

      private var mainMovie:MovieClip;

                  private function onLoadSWF(event:Event):void {

                      event.target.removeEventListener(Event.ADDED, onLoadSWF);

                      if(event.target.name == "introScreenMain") {   

                          mainMovie = MovieClip(event.target);                   

                      }               

                      if(event.target.name == "playButton") {

                          event.target.addEventListener(MouseEvent.CLICK, buttonPressed);

                      }

                      else if(event.target.name == "instructionButton") {                   

                          event.target.addEventListener(MouseEvent.CLICK, buttonPressed);

                      }

                  }

       

                  private function buttonPressed(event:Event):void {   

                      if(event.target.name == "playButton") {                   

                              navigator.replaceView(gameScreen);

                          }

                          else {

                             navigator.replaceView(signUp_screen);

                          }

                      }

                      if(event.target.name == "instructionButton") {                   

                          creditsLoader.load();

                          creditsLoader.addEventListener(MouseEvent.CLICK, creditsClosed);

                          creditsLoader.visible = true;

                      }               

                  }

       

      On Android, the above code works fine. On iOS, the buttons press but no events are firing.

       

      As an asside, I used to have the events as TouchEvents on Android but found MouseEvents to work great (I don't fully recall why I changed them from touch events way bach when but I do recall doing so). I did change the events to TouchEvents on iOS and that had no effect.

       

      Help?

        • 1. Re: Why does this work on droid but not iOS
          alinator11 Level 2

          Okay... I figured this all out after two days of frantic fumbling around. Here's how I did it...

           

          I built an alert object and ran the app in simulator to make the alerts show at points in the code. I found the alerts hanging here:

           

          private function onLoadSWF(event:Event):void {
          event.target.removeEventListener(Event.ADDED, onLoadSWF);
          //if(event.target.name.indexOf("instance") == -1) {
          //var hsa:AlertObject = new AlertObject();
          //hsa.alertMessage = "loading: " + event.target.name;
          //hsa.open(this, false);
          //}
          if(event.target.name == "introScreenMain") {
          mainMovie = MovieClip(event.target);
          mainMovie.play();
          }
          if(event.target.name == "playButton") {
          event.target.addEventListener(MouseEvent.CLICK, buttonPressed);
          }
          else if(event.target.name == "instructionButton") {
          event.target.addEventListener(MouseEvent.CLICK, buttonPressed);
          event.target.addEventListener(TouchEvent.TOUCH_END, buttonPressed);
          }
          }

           

          What I found when I ran that was that the instance names for the objects in the SWF never report in (they report in but as instance*** instead of "playButton" or whatever other name they should be). So, I go over to the swf and, recalling that I made a new directory for iOS versions of the SWF begin to have suspicions. Que the sinister music.

           

          I go to Flash Pro, open the fla, go to the "playButton", examine it in the library and sure enough the class that it ties to is listed right there next to the instance. I click properties and the check box and Flash Pro says, in effect, "No class exists on the class path want me to create one?". LOL. I tied all the ActionScript back into the SWF's and the two I've tested now work perfectly. Go figure.

           

          As a suggestion, could it be possible for Flash Pro to maybe error if the SWF has members referecing ActionScript that Flash Pro does not know exist? That would have saved me a ton of trouble and perhaps far more than that. Alternatively, I would not even write AS if the instance names were guaranteed to report in (wich they are not) as the name I gave them in the main app (explination below post). Flex is still freaking awesome though! 

           

          Sheesh. I'm glad that's over.

           

           

           

           

           

           

          ********************* I don't build the FLA's but I do often wind up publishing the final product in my version of Flash Pro. I know that all members of my FLA's have instance names. Usually, that makes no differnce and when I look for the name in Flex, I get "instanceXXX" instead of the name I am looking for. The only way I've found to guarantee that instance names show up from an SWF when I run my Flex app is to do the following and tie it to the SWF member via Flash Pro:

           

          public class InstructionsButton extends SimpleButton
          {
          public function InstructionsButton(upState:DisplayObject=null, overState:DisplayObject=null, downState:DisplayObject=null, hitTestState:DisplayObject=null)
          {
          super(upState, overState, downState, hitTestState);
          addEventListener(Event.ADDED_TO_STAGE, dispatchAdded);
          }
          public function dispatchAdded(event:Event):void {
          dispatchEvent(new Event(Event.ADDED, true));
          }
          }

           

          You sometimes also have to play with MovieClips to get the instances to load too (depending on where your designer declared an instance in the SWF timeline). That's not as big of a deal as long as you can be sure that if you declare a MovieClip instance that you're going to for sure be able to locate that instance when you load in Flex.

          • 2. Re: Why does this work on droid but not iOS
            pauland Level 4

            I hope you've tried this on a real Apple device. I think you'll find that loading swfs is going to be a problem.

            • 3. Re: Why does this work on droid but not iOS
              alinator11 Level 2

              I have and it is loading fine thus far. But I took many of the swf's out for

              testing. I will follow up when I get the full app redeployed.

              • 4. Re: Why does this work on droid but not iOS
                alinator11 Level 2

                I believe that SWF's load fine on iOS. I have tested on two devices now and both are fine. My app is a Flex logic layer loading in SWF's that were built in Flash Pro. I think the difference between iOS and any other platform is that you can load SWF in iOS but they have to be embedded in your app. iOS does not use just in time compile like Java, for instance, does. So, if I were sending SWF's down from a server, I'd have a problem. Since I've made them assets in the app, they load just fine because Flex can precompile them for iOS.

                • 5. Re: Why does this work on droid but not iOS
                  pauland Level 4

                  Ah, I skipped past the embed..