Having problem controling resizing of a swf from another swf

I'm trying to build a site where all the pages are full browser and maintain aspect ratio. I would like to control the resizing from the menu page.  The resizing works fine from the page that's being resized but when I try to let the parent swf do that it has issues.
Here's what the home page looks like with the controls built in  http://www.mespinach/example1/
This example is the site it has a menu page that I open the others from I remove the resizing code from the home page and try to resize from menu.swf.
here's the code from menu.swf
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
var holder:btnHolder = new btnHolder();
addChild(holder);
stage.addEventListener(Event.RESIZE, moveHolder);
moveHolder();
function moveHolder(e:Event = null):void {
    holder.x = stage.stageWidth - (holder.width +25);
    holder.y = 50;
holder.mcHome.buttonMode = true;
holder.mcAbout.buttonMode = true;
holder.mcMovies.buttonMode = true;
//holder.mcLocation.buttonMode = true;
holder.mcStore.buttonMode = true;
//var objFileToLoad:URLRequest = new URLRequest();
var swfLoader:Loader;
addListeners();
function addListeners():void {
    holder.mcHome.addEventListener(MouseEvent.CLICK, homePage);
    holder.mcAbout.addEventListener(MouseEvent.CLICK, aboutPage);
    holder.mcMovies.addEventListener(MouseEvent.CLICK, moviesPage);
    // holder.mcLocation.addEventListener(MouseEvent.CLICK, locationPage);
    holder.mcStore.addEventListener(MouseEvent.CLICK, storePage);
var currentPage:*;
var xImage:Sprite = new Sprite();
homePage();
function homePage(event:MouseEvent = null):void {
    SoundMixer.stopAll();
    addListeners();
    if(swfLoader){this.removeChildAt(0);}
    holder.mcHome.removeEventListener(MouseEvent.CLICK, homePage);
    var loadRequest:URLRequest = new URLRequest("home.swf");
    swfLoader = new Loader();
    swfLoader.contentLoaderInfo.addEventListener(Event.INIT, positionContent);
    swfLoader.load(loadRequest);
    this.addChildAt(swfLoader, 0);
    function positionContent(e:Event):void {
        currentPage = swfLoader.content;
        var loadedImage = currentPage.onStage;
        xImage = loadedImage;
//        loadedImage.x= 0;
//        loadedImage.y= 0;
        fillBG();
function aboutPage(event:MouseEvent):void {
    SoundMixer.stopAll();
    var objFileToLoad:URLRequest = new URLRequest("about.swf");
    loader.contentLoaderInfo.addEventListener(Event.INIT,positionContent);
    loader.load(objFileToLoad);
    this.addChildAt(loader, 0);
    function positionContent(e:Event):void{
       loader.x= 0;
       loader.y= 0;
function moviesPage(event:MouseEvent):void {
    addListeners();
    holder.mcMovies.removeEventListener(MouseEvent.CLICK, moviesPage);
    SoundMixer.stopAll();
    if(swfLoader){this.removeChildAt(0);}
    var objFileToLoad:URLRequest = new URLRequest("Movies.swf");
    swfLoader.contentLoaderInfo.addEventListener(Event.INIT,loadedHandler);
    swfLoader.load(objFileToLoad);
    this.addChildAt(swfLoader, 0);
    function loadedHandler(e:Event):void {
        currentPage = swfLoader.content;
        xImage = currentPage;
function locationPage(event:MouseEvent):void {
    SoundMixer.stopAll();
    var objFileToLoad:URLRequest = new URLRequest("location.swf");
    loader.load(objFileToLoad);
     this.addChildAt(loader, 0);
function storePage(event:MouseEvent):void {
    SoundMixer.stopAll();
    var objFileToLoad:URLRequest = new URLRequest("store.swf");
    loader.load(objFileToLoad);
     this.addChildAt(loader, 0);
holder.addEventListener(MouseEvent.MOUSE_OVER, over);
holder.addEventListener(MouseEvent.MOUSE_OUT, out);
holder.addEventListener(MouseEvent.MOUSE_DOWN, down);
holder.addEventListener(MouseEvent.MOUSE_UP, up);
holder.mcAbout.buttonMode = true;
holder.mcHome.buttonMode = true;
holder.mcMovies.buttonMode = true;
holder.mcStore.buttonMode = true;
//holder.mcLocation.buttonMode = true;
var myColor:ColorTransform = transform.colorTransform;
function over(e:MouseEvent):void {
    myColor.alphaMultiplier = 3;
    e.target.transform.colorTransform = myColor;
function out(e:MouseEvent):void {
    myColor.alphaMultiplier = 1;
    e.target.transform.colorTransform = myColor;
function down(e:MouseEvent):void {
    myColor.alphaMultiplier = 5;
    e.target.transform.colorTransform = myColor;
function up(e:MouseEvent):void {
    myColor.alphaMultiplier = 1;
    e.target.transform.colorTransform = myColor;
//var cpc = this.child.child.getChildByName("onStage");
//trace(cpc);
var ratio:Number;
var rRatio:Number;
ratio = xImage.height/xImage.width;
rRatio = xImage.width/xImage.height;
var newRatio:Number;
function fillBG(evt:Event = null):void {
    trace("width: " + xImage.width);
    trace("height: " + xImage.height);
    trace("ratio: " + ratio.toString());
    trace("rRatio: " + rRatio.toString());
    trace("newRatio: " + newRatio.toString());
    newRatio = stage.stageHeight/stage.stageWidth;
    holder.x = stage.stageWidth - (holder.width +25);
    holder.y = 50;
    if (newRatio > ratio) {
        trace("newRatio > ratio: ");
        xImage.height = stage.stageHeight;
        xImage.width = stage.stageHeight * rRatio;
    } else {
        trace("else");
        xImage.width = stage.stageWidth;
        xImage.height = stage.stageWidth * ratio;
    stage.addEventListener(Event.RESIZE, fillBG);
messages from trace statements here:
width: 939
height: 704
ratio: NaN
rRatio: NaN
newRatio: NaN
else
width: 561
height: 704
ratio: NaN
rRatio: NaN
newRatio: 0.49376114081996436
else
The height never changes
retio and rRatio are NaN even though they are the Quotient of numbers.

First, it is too much code to go through so I don't think I will give a complete answer. I assume this is a timeline code.
Here is what I was able to notice:
1. You declare the variables outside the scopes of the functions:
var ratio:Number;
var rRatio:Number;
ratio = xImage.height/xImage.width;
rRatio = xImage.width/xImage.height;
var newRatio:Number;
Naturally, they are NaN because neither xImage.height nor xImage.width are available at this point.
I suspect that you anticipate that when code hits these lines - swf is already loaded but IT IS NOT. Flash executes ALL THE CODE to the end NOT WAITING for swf to load - this is one of the premises of asynchronous event model.
To remedy this you need to place value assignments into the event handler:
Version One:
Declare variable at the top of the code before you start loading:
var ratio:Number;
var rRatio:Number;
var newRatio:Number;
Calculate values in event handler:
function positionContent(e:Event):void {
        ccurrentPage = swfLoader.content;
        var loadedImage = currentPage.onStage;
        xImage = loadedImage;
        ratio = xImage.height/xImage.width;
        rRatio = xImage.width/xImage.height;
        fillBG();
Or do it inside  fillBG(); method (version two)
2. Nested functions are evil and I would like to suggest you reconsider using them and bring them outside of other methods' scopes. I am talking about positionContent handlers you use.

Similar Messages

  • Error when opening swf from another swf

    Hi all,
    I'll try to explain this as good as possible.... I made a maze game that works perfectly when I run it by clicking on it's own .swf file, but when I try to access it from another .swf file which is a menu for the games I created, it does not work.
    I have absolutely no idea where to look for the error, so my question is: can it be that the main.swf (which is the menu for games) could be the problem, or the problem must be in the maze.swf?
    Thanx in advance!

    no, all code is in the first frame of actions layer:
    stop();
        var rightArrow:Boolean = false;   
        var leftArrow:Boolean = false;
        var upArrow:Boolean = false;
        var downArrow:Boolean = false;
        var speed:int = 5;
        stage.addEventListener(KeyboardEvent.KEY_DOWN, stage_onKeyDown);
        stage.addEventListener(KeyboardEvent.KEY_UP, stage_onKeyUp);
        stage.addEventListener(Event.ENTER_FRAME, stage_onEnterFrame);
        function stage_onKeyDown(event:KeyboardEvent):void {
            if(event.keyCode == Keyboard.RIGHT) rightArrow = true;
            if(event.keyCode == Keyboard.LEFT) leftArrow = true;
            if(event.keyCode == Keyboard.UP) upArrow = true;
            if(event.keyCode == Keyboard.DOWN) downArrow = true;
        function stage_onKeyUp(event:KeyboardEvent):void {
            if(event.keyCode == Keyboard.RIGHT) rightArrow = false;
            if(event.keyCode == Keyboard.LEFT) leftArrow = false;
            if(event.keyCode == Keyboard.UP) upArrow = false;
            if(event.keyCode == Keyboard.DOWN) downArrow = false;
        function stage_onEnterFrame(event:Event):void {
            var rect:Rectangle = player.getBounds(this);
            var i:int = 0;
            var xBump:int = 0;
            var yBump:int = 0;
            if(rightArrow) {
                xBump = speed;
                for(i = 0; i < speed; i++) {
                    if(maze.hitTestPoint(rect.right + i, player.y, true)) {
                        xBump = i - 1;
                        break;
            if(leftArrow) {
                xBump = -speed;
                for(i = 0; i < speed; i++) {
                    if(maze.hitTestPoint(rect.left - i, player.y, true)) {
                        xBump = -i + 1;
                        break;
            if(upArrow) {
                yBump = -speed;
                for(i = 0; i < speed; i++) {
                    if(maze.hitTestPoint(player.x, rect.top - i, true)) {
                        yBump = -i + 1;
                        break;
            if(downArrow) {
                yBump = speed;
                for(i = 0; i < speed; i++) {
                    if(maze.hitTestPoint(player.x, rect.bottom + i, true)) {
                        yBump = i - 1;
                        break;
            player.x += xBump;
            player.y += yBump;
            if(rightArrow) {
                xBump = speed;
                for(i = 0; i < speed; i++) {
                    if(cilj.hitTestPoint(rect.right + i, player.y, true)) {
                        xBump = i - 1;
                        nextScene();

  • Having problem to enable my wifi setting from few days can any 1 help me???????????

    having problem to enable my wifi setting from few days can any 1 help me???????????

    Go to Settings/General/Reset - Erase all content and settings. the connecto to iTunes and restore as a New phone. Do not restore any backup. If the problem persists you have a hardware problem. Take it to Apple for exchange.
    This assumes that the phone is not hacked or jailbroken. If it is you will have to go elsewhere on the internet for help.

  • I have a new iMac but having problems installing final cut express 4 from old macbook pro ?

    i have a new iMac but having problems installing final cut express 4 from old macbook pro ?

    FCE was discontinued nearly 3 years ago and is no longer supported.
    I don't know whether it's possible to install it on Mavericks and if you do it may not perform properly.
    Final Cut pro X and iMovie are the only Apple apps that are supported.

  • How to call one .SWF from another?

    How do I call one .SWF from another. I built a very beefy
    base .SWF, and want to add music overlay, and an intro slide show
    to the exsting Flash animation, but put it in a second .FLA/.SWF
    file. How do I call one from the other?
    This will be embedded in an HTML file but I assume this is
    superfluous to my question.
    F.Z.

    I think you should open that Another SWF (FLA),
    and add some actionscript..
    For example, you could create a movie clip, and write
    actionscript in the
    first keyframe:
    loadMovie("
    http://www.somewebpage.com/movie.swf",
    this);
    "FredZimmerman" <[email protected]> wrote in
    message
    news:ftnjas$mj5$[email protected]..
    > How do I call one .SWF from another. I built a very
    beefy base .SWF, and
    > want
    > to add music overlay, and an intro slide show to the
    exsting Flash
    > animation,
    > but put it in a second .FLA/.SWF file. How do I call one
    from the other?
    >
    > This will be embedded in an HTML file but I assume this
    is superfluous to
    > my
    > question.
    >
    > F.Z.
    >

  • How to unload swf from anather swf

    I am calling 3 different swf in to test.swf.
    now i want to unload only 1 swf from test.swf
    can any 1 tell me how it is possible i am trying
    with removeMoviClip() and unloadMovie()
    but its of no use.
    regards
    Justbipin

    Maybe that's not really what you're doing?
    I would guess you rather have
    loadMovieNum("myFiLe.swf",99);
    This would be unloaded with
    unloadMovieNum(99);
    Good luck
    Wolf
    PS Or do you have a container movieClip called "99" to fool
    us all? :-)
    PPS watch your capitalization. If you call a file "myFiLe"
    (and mis-spell it somewhere) it might work on Windows, but not on
    Unix-derivatives. A potential source of "Why did it work when I
    tested it but not when I uploaded it?"

  • RemoveChild in parent.swf from child.swf (AS3)

    Hi! How do I remove a child from a parent timeline with an externally-loaded swf? Specifically, I have a main.swf that loads movie_1.swf and movie_2.swf. In the movie_1.swf, I have a button to remove movie_2.swf from main.swf.
    //--------- main.swf code:
    var loader1:Loader = new Loader();
    var loader2:Loader = new Loader();
    loader1.load(new URLRequest("movie_1.swf"));
    loader2.load(new URLRequest("movie_2.swf"));
    addChild(loader1);
    addChild(loader2);
    //------------- movie_1.swf code:
    removeMovie2_btn.addEventListener(MouseEvent.CLICK , removeMovie2);
    function removeMovie2(event:MouseEvent):void
    this.parent.parent.removeChild(this.loader2); // this does not work (get error code 2007, "Parameter child must be non-null")
    // Thank you!

    Here's how your code will change:
    //--------- main.swf code:
    var loader1:Loader = new Loader();
    var loader2:Loader = new Loader();
    loader1.contentLoaderInfo.addEventListener(Event.COMPLETE, assignMovie1Listener);
    loader1.load(new URLRequest("movie_1.swf"));
    loader2.load(new URLRequest("movie_2.swf"));
    addChild(loader1);
    addChild(loader2);
    function assignMovie1Listener(evt:Event):void {
          MovieClip(evt.currentTarget.content).addEventListener("eventTriggered", removeLoader2);
    function removeLoader2(evt:Event):void {
          loader2.unloadAndStop();
          removeChild(loader2);
    //------------- movie_1.swf code:
    removeMovie2_btn.addEventListener(MouseEvent.CLICK , removeMovie2);
    function removeMovie2(event:MouseEvent):void
          dispatchEvent(new Event("eventTriggered"));

  • Anyone having problems with art/animation/audio disappearing from the timeline after a save?

    Hello,
    I'm having problems with many files losing their assets from the timeline after a save and reopening the file in Mac OS X Snow Leopard. This is happens quite often now and there seems to be no pattern to it. For example, I will open an existing Flash animation complete with sound and artwork, make changes to the animation timing, test the SWF and everything looks good, then save. After reopening the exact same file, there will be audio that was on the timeline will be an empty frame. In addition, there is art work that was swapped out or updated to a character and the symbols becomes empty after reopening. I'm losing days and hours of work and I can't seem to find any answers or help to figure out what's going on.
    Any insight would be appreciated!
    thanks!

    I now use CS5.5 but I've noticed it on every version since CS4.
    I JUST ran the latest update to 11.5.1.349
    I'll let you know if it continues but for now I'm planning to learn a new software. Finally have some time to focus on this and if it works out I may say so long to Flash. I'll give CS6 a try but if it's not SIGNIFICANTLY improved (Brush tool comparable to ToonBoom, No losing data, Better Playback, Ability to export HTML5), it's just not worth it anymore. I've been using Flash since version 1 and since Adobe took it over, I hate to say that anything other than actionscript has gone WAY downhill. Many new features but they don't actually work well, or crash at runtime if used beyond a tutorial's level intensity. What's the point of all that functionality if it looks like garbage and can't perform on a professional level? Even if you do take the extra time to work slowly or limited to make it look nice - it loses the data! or now without HTML5 your venues of use are sliced in half? Pointless. I don't want to trash all my Flash experience, but I'm done defending an inferior product and waiting for it to catch up to a modern professional standard. I think my Flash days may be over very soon unfortunately. I feel like the're more interested in defending what they've created, than in making it work or even asking us what we want. I feel like a Girlfriend who's Man keeps promising to get steady work but hasn't after 10 years. Flash...we need to talk.

  • Control swf from separate swf in main file

    Im loading 2 swfs into my main swf. So I have a top swf and a
    bottom swf being loaded in externally into my main swf that makes 3
    swfs, 1MAIN swf loading TOP swf & BOTTOM swf.
    Is there a way to have the bottom swf control or command the
    top swf? I need a button on in the bottom swf to tell the top swf
    to load a movie.

    in AS2 you can point directly from one to the other with the
    correct pathing.
    IE:
    _level0.TopSwfLoader.content.FunctionToCall();
    or
    _level0.TopSwfLoader.content.Property = NewPropertyValue;
    _level0 takes you to the main swf (_root, but this works
    around if lockroot is set)
    TopSwfLoader.content is the content of the Loader component
    that has your Top.swf loaded into it. If you are not using a Loader
    component, then you can change this to the instance name of the
    Movie Clip that has the swf loaded into it.
    FunctionToCall()/Property is what you want to control. Either
    a function call or a property.
    In AS3 this works a bit differently. I would dispatch a
    custom event from the Bottom swf. Then the main swf would catch
    that event, and call the appropriate function/property in the top
    swf. I can elaborate more on this if you need.

  • I am having problems uploading my book to blurb from Lightroom 5

    I am hiving problems uploading my book to blurb from Lightroom 5

    Were you able to properly login to Blurb before uploading ?

  • Stop another SWF movie (+ sounds) from another SWF

    Hiya there
    Thank you in advance for skim reading this and thinking if
    you can help!
    I've search and seen similar problems, but not the same.
    THE PROBLEM / CHALLENGE!
    I need a selection of simple SWF movie files with audio
    attached. They're basically audio buttons, scattered through a HTML
    page. At the moment they're set up with sound to 'stream' attached
    to a specific frame - then enough frames to cover the duration of
    the sound.
    - on press of button it skips to Frame2 where the button
    status changes and the sound plays
    - if during that playing process, the button is clicked
    again, then it jumps back to Frame1 and rests
    I've played with the StopAllSounds command, but that just
    stops the sounds on the other SWFs and doesn't stop (and revert)
    the other SWFs back to their Frame1's.
    Is this something i can solve with simple Action Script /
    Behaviours... or do i need to fiddle with the Javascript in the web
    page?
    Thank you in advance for any help
    cheers
    James

    "MrIzzard" <[email protected]> wrote in
    message news:e3l5nr$bdo$[email protected]..
    > But surely if the way i'm currently playing audio is
    from being attached into
    > the frames in the timeline (at the moment if i press a
    button to switch the
    > movie back to Frame 1, where there's no audio attached,
    the sound stops) - then
    > this would work for other frames too.
    > Does that make sense?
    If your swfs are on separate places on an html page (not one
    swf loaded by another swf) then you can use localConnection to
    communicate between swfs.
    There are some MX version 6 examples on my website where one
    swf controls one or more others..
    http://members.cox.net/4my2dogs/flash/
    You can have the receiving end stop sounds or move to a
    different frame etc.
    tralfaz

  • Control access of a form from another form.

    hi all,
    Please help me .
    This is a system which contains a lot of forms (more than 100) . The system administrator can specify whether a user can insert, update,delete or query for each form (this varies for each user). So, when a user logs in and calls a form i have to enable / disable the insert, update,delete or query according to the user who has logged in and the privileges the system administrator has given for that form.
    i used the call_form method with query_only mode and no_query_only(normal mode) option . The normal mode allows insert,update,delete and query together but i want the user to insert into database without querying any of the records.
    So, in short , i would like to know if i can enable/disable insert,update,delete & query of a called form(Form B) from calling form (Form A) without having to modify (Form B) and without issuing any grant statements in the database side ? Is there any option like the one in the call form method?
    Thanking you in advance.

    Thank you very much for the response.
    yes, set form property and set block property can be used when i want to enable / disable insert in the current form. But, what if i want to control enable/disable insert from another form (the main form) ????
    Can i pass parameters ? without making any change in the current form.

  • Component Slider not working when loaded from another swf file

    I have a simple Flash application that uses a component Slider to increase or decrease the size of the text in a TextArea (ta). It works perfectly fine on its own, however, when I try to load the same swf file from another application, I get the following error...
    ReferenceError: Error #1069: Property fl.managers:IFocusManager::form not found
    on fl.managers.FocusManager and there is no default value.
    at fl.controls::Slider/thumbPressHandler()
    Code...
    import fl.events.*;
    import flash.text.TextFormat;
    ta.text = "Lorem ipsum dolor sit amet";
    var tf:TextFormat = new TextFormat();
    tf.color = 0xCCCCCC;
    tf.font = "Trebuchet MS";
    tf.size = 12;
    slider.addEventListener(SliderEvent.THUMB_DRAG, sliderChange);
    style();
    function style():void
        ta.setStyle("textFormat", tf);
    function sliderChange(e:SliderEvent):void
        tf.size = slider.value;
        ta.setStyle("textFormat", tf);
    Could the containing swf file that I'm loading the slider swf file in anyway effect the slider application? I don't quite understand why it works on its own, but not when loaded from another app.

    add a slider component to the main (loading) swf's library.

  • How to call a method in a flash file (swf) from another fl;ash file (swf) and vica versa ?

    Hi, I have a Flash file (Flash1.fla). I have a  public method, method1() in a public class of the file. I have another Flash file (Flash2.fla). I have a public method, method2()  in the public class of this file. I want to call the method1() from Flash2.swf and the method2() from Flash1.swf. Please help!!

    swf-to-swf communication
    http://kb2.adobe.com/community/publishing/918/cpsid_91887.html

  • Opening a swf from other swf

    Hello Readers,
    I have been working on an application.
    There is a login screen for the application, in one of the swf's I have been writing the login code, along-with communications with XML.
    Now once the user has been validated, I want to redirect the user to some XYZ.swf  file and close the login.swf file else if not then I have to display an error message.
    The issue may sound simple, but I am a beginner at this.
    I would be encouraged to explore my endeavors, if some one could help me out with it.
    Thank You for reading.
    Regards,
    Jayesh Sidhwani

    Absolutely! Yup, you got it! If you want to use a SWF with all its script and interactions, you have to put it in another place and treat it as an external URL. It has to be boss of its territory (I almost said 'domain' but of course it can be in the same domain).
    Go navigateToURL() and you have no problems.
    The problem is, we often want to load a SWF without navigating outside our main compiled SWF, and it's frustrating to find out that it loads but doesn't use its timeline code. When you want to do this, you should forget using a SWF and make the object an MC instead.

Maybe you are looking for