14 Replies Latest reply on Apr 3, 2011 10:42 PM by Aaron-009

    using swf inside my flash project

    Aaron-009

      Hi,

       

      I'm currently trying to use a swf file inside my flash project. I have actually found a half solution in that loadMovieNum does what I want, except I want the external .swf to be inside my project, and so it's compiled into the same .swf. This would then mean that the external .swf doesn't need to be present thereafter.

       

      Really need a response to this, all help is much appreciated!

      Cheers.

        • 1. Re: using swf inside my flash project
          kglad Adobe Community Professional & MVP

          you can copy all the frames/layers from the external swf's main timeline and paste them into a movieclip.  attach and remove the movieclip at appropriate times.

          • 2. Re: using swf inside my flash project
            Aaron-009 Level 1

            Hi,

             

            thanks for your fast response. I have tried this, however the external movie (it's a small game) interacts with my current project. When the game moves from 1 frame to another (obviously thats within the movieclip) for some reason my main movie skips back to the first frame for no apparent reason.

             

            Thanks

            • 3. Re: using swf inside my flash project
              Aaron-009 Level 1

              Just to make my problem a bit clearer: I essentially need to be able to grab the swf from the library so there isn't the need for another .swf kicking around somewhere. I don't want my main project to break just because it's moved >_>

              • 4. Re: using swf inside my flash project
                sagaro

                Hi,

                Try to lockroot the loaded swf movie..

                1 person found this helpful
                • 5. Re: using swf inside my flash project
                  Aaron-009 Level 1

                  Hi thanks for your reply. Lockrooting majorly fixed the entire issue when importing the entire swf as a moveclip. Only problem is the timers on the game no longer seem to work, the numbers on the hud just stay at 0. Any idea as to why this may have happened?

                   

                  Cheers

                   

                  Edit: pretty sure timers are working, just not updating to the hud

                  • 6. Re: using swf inside my flash project
                    sagaro Level 1

                    Can I see the timer script?

                    • 7. Re: using swf inside my flash project
                      Aaron-009 Level 1

                      Taken from a basic tutorial here http://www.gamesheep.com/free/flash-tutorials/1-flash-racing-game-1/step1.php

                       

                      function step(who) {
                           //check to see if the car in question is controlled by the player or by the computer
                           if (_root["car"+who].code == "player") {
                                //we will constantly decrease speed by multiplying it with a number below 1
                                if (this["speed"+who]>0.3) {
                                     this["speed"+who] *= _root.speedDecay;
                                } else {
                                     this["speed"+who] = 0;
                                }
                                //the car will react to certain keys
                                //accelerate
                                if (Key.isDown(Key.UP) && this["speed"+who]<_root.maxSpeed) {
                                     //if the acceleration key is down, the engine sound volume is set to 100
                                     this["speed"+who] += _root.acceleration;
                                }
                                //brake (reverse)    
                                if (Key.isDown(Key.DOWN)) {
                                     this["speed"+who] -= _root.backSpeed;
                                }
                                //steer left     
                                if (Key.isDown(Key.LEFT) && Math.abs(this["speed"+who])>0.3) {
                                     _root["car"+who]._rotation -= _root.rotationStep*(this["speed"+who]/_root.maxSpeed);
                                }
                                //steer right     
                                if (Key.isDown(Key.RIGHT) && Math.abs(this["speed"+who])>0.3) {
                                     _root["car"+who]._rotation += _root.rotationStep*(this["speed"+who]/_root.maxSpeed);
                                }
                                this["rotation"+who] = _root["car"+who]._rotation;
                                //we calculate the two components of speed (X axis and Y axis)
                                this["speedx"+who] = Math.sin(this["rotation"+who]*(Math.PI/180))*this["speed"+who];
                                this["speedy"+who] = Math.cos(this["rotation"+who]*(Math.PI/180))*this["speed"+who]*-1;
                                //apply the components on the actual position of the car
                                _root["car"+who]._x += this["speedx"+who];
                                _root["car"+who]._y += this["speedy"+who];
                                //the collisions
                                //define the four collision points
                                _root["car"+who].pointLeft = {x:-20, y:0};
                                _root["car"+who].localToGlobal(_root["car"+who].pointLeft);
                                _root["car"+who].pointRight = {x:20, y:0};
                                _root["car"+who].localToGlobal(_root["car"+who].pointRight);
                                _root["car"+who].pointFront = {x:0, y:-25};
                                _root["car"+who].localToGlobal(_root["car"+who].pointFront);
                                _root["car"+who].pointBack = {x:0, y:25};
                                _root["car"+who].localToGlobal(_root["car"+who].pointBack);
                                //let's use some shorter variable names :)
                                this["lpx"+who] = _root["car"+who].pointLeft.x;
                                this["lpy"+who] = _root["car"+who].pointLeft.y;
                                this["rpx"+who] = _root["car"+who].pointRight.x;
                                this["rpy"+who] = _root["car"+who].pointRight.y;
                                this["fpx"+who] = _root["car"+who].pointFront.x;
                                this["fpy"+who] = _root["car"+who].pointFront.y;
                                this["bpx"+who] = _root["car"+who].pointBack.x;
                                this["bpy"+who] = _root["car"+who].pointBack.y;
                                //check for collisions
                                if (_root.terrain.hitTest(this["lpx"+who], this["lpy"+who], true)) {
                                     _root["car"+who]._rotation += 5;
                                     this["speed"+who] *= 0.85;
                                }
                                if (_root.terrain.hitTest(this["rpx"+who], this["rpy"+who], true)) {
                                     _root["car"+who]._rotation -= 5;
                                     this["speed"+who] *= 0.85;
                                }
                                if (_root.terrain.hitTest(this["fpx"+who], this["fpy"+who], true)) {
                                     this["speed"+who] = -1;
                                }
                                if (_root.terrain.hitTest(this["bpx"+who], this["bpy"+who], true)) {
                                     this["speed"+who] = 1;
                                }
                                //position the shadow of the car     
                                _root["shadow"+who]._x = _root["car"+who]._x-4;
                                _root["shadow"+who]._y = _root["car"+who]._y+2;
                                _root["shadow"+who]._rotation = _root["car"+who]._rotation;
                                //checkpoints
                                if (_root["car"+who].hitTest(_root["checkpoint"+_root["currentCheckpoint"+who]])) {
                                     //if the current checkpoint is the start line - increase the lap number
                                     if (_root["currentCheckpoint"+who] == 1) {
                                          if (_root["currentLap"+who] != 0) {
                                               _root.setBestLap();
                                          }
                                          if (_root["currentLap"+who] == _root.totalLaps) {
                                               _root.gotoAndStop("finish");
                                          } else {
                                               _root["currentLap"+who]++;
                                          }
                                          _root.currentLapTXT = _root["currentLap"+who]+"/10";
                                     }
                                     _root["currentCheckpoint"+who]++;
                                     //if the current checkpoint is the last checkpoint - set the next checkpoint to the start line
                                     if (_root["currentCheckpoint"+who]>_root.checkpoints) {
                                          _root["currentCheckpoint"+who] = 1;
                                     }
                                }
                           }
                           if (_root["car"+who].code == "computer") {
                           }
                      }
                      function setTimes() {
                           timeElapsed = getTimer()-_root.initialTime;
                           milliseconds = timeElapsed;
                           seconds = Math.floor(milliseconds/1000);
                           minutes = Math.floor(seconds/60);
                           minutesTXT = minutes;
                           secondsTXT = seconds-minutes*60;
                           tensTXT = Math.round((milliseconds-seconds*1000)/10);
                           if (minutesTXT<10) {
                                minutesTXT = "0"+minutesTXT;
                           }
                           if (secondsTXT<10) {
                                secondsTXT = "0"+secondsTXT;
                           }
                           if (tensTXT<10) {
                                tensTXT = "0"+tensTXT;
                           }
                           _root.totalTimeTXT = minutesTXT+"."+secondsTXT+"."+tensTXT;
                      }
                      function setBestLap() {
                           bestTime = getTimer()-_root.lapTime;
                           milliseconds = bestTime;
                           if (oldMilliseconds>milliseconds || oldMilliseconds == null) {
                                oldMilliseconds = milliseconds;
                                seconds = Math.floor(milliseconds/1000);
                                minutes = Math.floor(seconds/60);
                                minutesTXT = minutes;
                                secondsTXT = seconds-minutes*60;
                                tensTXT = Math.round((milliseconds-seconds*1000)/10);
                                if (minutesTXT<10) {
                                     minutesTXT = "0"+minutesTXT;
                                }
                                if (secondsTXT<10) {
                                     secondsTXT = "0"+secondsTXT;
                                }
                                if (tensTXT<10) {
                                     tensTXT = "0"+tensTXT;
                                }
                                _root.bestLapTXT = minutesTXT+"."+secondsTXT+"."+tensTXT;
                           }
                           _root.lapTime = getTimer();
                      }
                      
                       
                      

                      I can't really figure out how its updating the hud in the first place if I'm honest o.o

                      • 8. Re: using swf inside my flash project
                        sagaro Level 1

                        So the timer is working. The issue is updating the hud...what do you mean by the "hud"..sorry to ask..Also, is the game online? Can I view and test it?

                        • 9. Re: using swf inside my flash project
                          Aaron-009 Level 1

                          By hud I just meant the score screen. I'm not sure how the game is supposed to be updating the numbers on the screen. There doesn't seem to be specific regions with their own instance names, only variables in the code. My own game isn't online, but you can play the one provided in the tutorial here http://www.gamesheep.com/free/flash-tutorials/1-flash-racing-game-1/step4.php

                           

                          Thanks

                          • 10. Re: using swf inside my flash project
                            sagaro Level 1

                            Hi,

                            I downloaded the files and test it.

                            I load it thru loadMovieNum("test.swf", 0) and test my driving skills. It does update Current Lap, Best Lap and Total Time(presuming these are the hud)

                            • 11. Re: using swf inside my flash project
                              Aaron-009 Level 1

                              Hi,

                               

                              that's correct however I'm using the file in a different context. I've taken all the frames/assets and put them in my other project in the form of a movieclip. After rootlocking the as2 in the movieclip I get the problem

                               

                              Regards

                              • 12. Re: using swf inside my flash project
                                sagaro Level 1

                                I also tried it this:

                                my_movieclip.loadMovie("test.swf")

                                It is also perfectly working. Unless you have loaded the movie in a different way..

                                • 13. Re: using swf inside my flash project
                                  Aaron-009 Level 1

                                  Hi

                                   

                                  as I've said, I didn't load the game from an external file, I took all the assets/frames and put them in a movieclip in my own project, as stated by someone earlier in this thread. The problem then occurred after I rootlocked the movieclip following your advice.

                                   

                                  Cheers

                                   

                                  Edit: found something; the source for those figures which I'm having the problem with is linked via 'variable' under the 'options' panel for each dynamic text. They were set to root.variablename wich may explain why they stopped working when I rootlocked it. However, I'm unsure as to how I can get it working again.

                                  • 14. Re: using swf inside my flash project
                                    Aaron-009 Level 1

                                    Fixed.


                                    So the scores panel was in its own movie clip, while using the root prefix to access the variables controlling each set of numbers. However, with rootlock on that didn't work. I simply dispanded the movie clip so that the numbers were on the same level as everything else and removed the root prefix and it all worked. Thanks all for your help

                                    Cheers