How to center loaded swf & get screen coordinates of its component?

I made an swf using Flash CS4, it has a movieclip named 'mc' & and a vertical bar centered horizontally. I then load it using swfloaded & put it inside a canvas & set it's windows & height to 100%.
The codes:
<mx:Canvas id="cv" verticalScrollPolicy="off" horizontalScrollPolicy="off" width="{screen.width}" height="{screen.height}">
  <mx:SWFLoader id="template" source="assets/sample.swf" width="100%" height="100%"  complete="dump(event);"/>
  <mx:HBox id="bb" />
</mx:Canvas>
<mx:Script>
private function dump(event:Event): void {
     var panel:MovieClip = MovieClip(template.content);
     var pt:Point = panel.localToGlobal(new Point(panel.mc.x, panel.mc.y));
     bb.x = pt.x; bb.y = pt.y; bb.width=10; bb.height = 10;
     panel.x = (cv.width - panel.conentWidth) / 2;
     Alert.show(
          "scaleratio x,y = " + panel.scaleX + "," + panel.scaleY +"\n"
          + "panel x,y = " + panel.x + "," + panel.y + "\n"
          + "local x,y = " + panel.mc.x + "," + panel.mc.y + "\n"
          + "global x,y = " + pt.x + "," + pt.y + "\n"
</mx:Script>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The dump result is:
scaleratio x,y = 1,1
panel x,y = 100,800
local x,y = 775, 800
gloval x,y = 875, 800
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Q1. I draw an bound box according to the content object of this swf & saw this bound box is indeed centered. However, the bar object is some offset left from the center of screen. Why it's not aligned center as I saw it in Flash CS4?
Q2. I try to get the screen coordinates of component 'mc' by using localToGlobal to convert it to screen coordinates & draw a box to overlap their top-left point. However the topleft point of box is far left of mc's on screen. I think it's due to the swf is scaled, so I dump scaleX and scaleY of this swf but they are both 1? How can I get correct screen coordinates of mc?
Thanks in advance!
Scott

Because of margins and padding, the Canvas probably won't be positioned at
0,0, so setting its width to screen.width will make it hang over the right
edge.  Use width="100%" instead.  Same for height.
I believe there is a horizontalAlign property on the SWFLoader.

Similar Messages

  • Get screen coordinates from 3d position

    Hi,<br />When I use 3d JavaScript camera's getScreenFromPosition method, the screen Y returned is always 0. The following is the test code. Did I miss anything? Is there another way to get screen coordinates from 3d?<br /><br />I'd appreciate any help.<br /><br />Xintai<br /><br />// test code ==========================<br />function v3dToScreen(v,w,h)<br />{<br />   console.println("\n v=" + v + "  w = " + w + "  h ="+ h);<br />   cam = scene.cameras.getByIndex (0);<br />    <br />   screenV = cam.getScreenFromPosition(v, w, h);<br />   console.println( " converted: mx=" + screenV.x + "    my=" + screenV.y);<br />   console.println(screenV.toString());<br />   //console.println( " pdf mouse X=" + host.mouseX + "   pdf mouse Y=" + host.mouseY);<br />}<br /><br />console.println ("Click a 3D object to test getScreenFromPosition()");<br /><br />myMouseHandler = new MouseEventHandler();<br />myMouseHandler.onMouseDown = true;<br />myMouseHandler.onEvent = function(event)<br />{<br />   if(event.isMouseDown) {<br />    console.println("====== MouseDown =======");<br />    console.println("isMouseDown           = " + event.isMouseDown );<br />    <br />    for ( i=0; i<event.hits.length; i++ )<br />    {<br />         console.println ("   hits[" + i + "].position   = " + event.hits[i].position );<br />        <br />        if (event.hits[i].target != undefined)<br />        {<br />                        v3 = vent.hits[i].position;<br />                        v3dToScreen(v3,event.canvasPixelWidth,event.canvasPixelHeight);<br />        }<br />    }<br />   }<br />}<br /><br />runtime.addEventHandler(myMouseHandler);<br /><br />// end of test code ==========================

    Hi Xintai,
    This is a feature i would also like to use. I've tried using the script that you've provided but i cant get it to work. I assume this is the javascript (.js file) that you embed into the pdf? Is this all that's needed?
    If you've managed to get this working, could you let me know how you did it?
    Thanks
    George

  • How to Center Align SWF in Browser

    I used the publish feature of flash but it does not seem to center the SWF in the browser. Why is there a centering feature on the publish settings under HTML tab if it does not center the SWF? It only works if you set Dimensions to Percent but that exposes the area beyond the stage and i don't want it to be seen. In addition that causes some movieclips to be improperly positioned. The Flash Alignment should have been disabled if the Dimensions is not set to Percent. Does anybody disagree? Can somebody help me solve this issue? Perhaps a simple script that centers my swf file in a browser... Any help highly appreciated.

    Thanks a many for your help! I tried not using the swfobject.js and tried commenting out the object instantiation in the html file and it still works, why? Is it really needed? What exactly is the purpose of the swfobject.js. I remember i read something about Geoff Stearns creating that .js file to solve a particular problem but i forgot what exactly that was.

  • Get mouse coordinates when its moved over a powerpoint slideshow -URGENT

    i am writing a code to get the mouse coordinates as its moved over the screen(especially over powerpoint slide show. plz help me if u know a simple code that perform this function without a plug-in, but if i have to use a plug-in advice me.
    tahnk u very much :)

    sorry for not using the code tags..just learn about it...thanx
    my problem is.when i want to record every coordinates of the mouse while it moves..but using the printstream,it only records the end point of the mouse and not while the mouse moves/dragged.I'm developing a sketch pad program. the program needs to capture the coordinates and saved it into a file.i tried using it but keeps on saving the last point but not all
    example
    point A..........................point N............................point Z
    i want the program to save the coordinate of point A,point B,C,D...point N....and last point Z
    but it keeps on saving only point Z.can u help or give any ideas..thanx

  • How to center loaded image?

    First time building an app for AIR, from Flash CS4, as I needed to be able to write to a local XML file... all is working except I cannot manage to center a loaded image properly. I am running it full screen and everything I try width / height wise gives me my desktop resolution - which I guess is right since it's full screen. However positioning goes from the stage's top/left corner - not the monitor's top/left corner.
    This image illustrates the issue - when I query the size I get the red rectangle size... but when I position something it uses the green rect - ie the actual stage. How do I fix in AIR?

    is you stage align property set to StageAlign.TOP_LEFT ?

  • How do I load a print screen image into a picture indicator?

    Hi,
    I am trying to load a printscreen image into a picture indicator without first saving it. I am currently doing it by acquiring and saving a print screen image, then reloading and displaying the bitmap file. This works, but it is not elegant and the colors are displayed wrong. (The SnapView.vi is from the G Toolbox for LabVIEW) Thanks for your help.
    Peter Buerki
    Attachments:
    Test PrintScreen.vi ‏29 KB

    Hello –
    When you push the print screen button in your keyboard, the image is send (temporarily stored) to the clipboard.
    You could call the Windows API to recover that image and send it to an indicator in the front panel. This Example Program can show you how to make Windows API calls; I think you might find it useful to get started in programming your application.
    Hope this helps.
    SVences
    Applications Engineer
    National Instruments

  • How does a loaded swf talk back to the main movie?

    Hi,
    I'm new to as3 and have troubles finding the right path for
    swfs to "talk" to one another.
    In my movie, I load an swf "news.swf" into a mc called
    container_mc.
    At one point I want to swap the "news.swf" to "ueberuns.swf"
    via button click in my main movie, but not directly: "news.swf" has
    a frame labeled "out", which builds down some elements over appr.
    20 frames. In the last frame of "news.swf", I want "news.swf" to
    either load the next "ueberuns.swf" into that same container_mc of
    my main movie or have my main movie find out that "news.swf" is
    through with it's last frame and then throw out "news.swf" and put
    "ueberuns.swf" in that container_mc.
    I already found out that I address "news.swf" by the
    following code:
    if (newsLaden.content != null) {
    newsLaden.content.gotoAndPlay("out");
    where newsLaden is the Loaders name. But how do I get
    "news.swf" to reply?
    Anyone can help? Thanks a lot!
    Cheers, Karl

    This is one of the biggest problems of AS3 as communication
    between swfs, levels, and nested MCs has taken a completely
    different path than the previous 9 versions of Flash. Both Erick's
    and TheWabbit's suggestions will work but I sort of follow Erick's
    approach as LocalConnection is the perfect fit for .swfs
    communicating in the same HTML page not for nested. The key is
    defining the timelines of MovieClips in each class when you want to
    tell them to do something.
    Try tera's example and see if that helps but if you
    understand Erick's approach keep going. I just wanted to add that
    you have to start thinking about defining the MCs you want to
    communicate with in each Object Class file such as:
    var _root:MovieClip = new MovieClip(parent);
    and then you can always sort of define who you want to talk
    to a bit easier.
    THIS REALLY REALLY SUCKS for those of us who have been with
    Flash since version 2 because they took away one of the best and
    easiest things to do (but I'm glad telltarget is gone!! lol). Now I
    fear people are going to start throwing everything back into one
    LARGE SWF again thereby undoing all the work we in the Flash
    community did in the first ten years to define 'best practices'
    and_levels definitely was one of them along with an 'actions'
    layer. I think Adobe's programmers who joined the Macromedia guys
    led the product somewhere it didn't necessarily need to go. The
    problem is many didn't know how to use the Flash Community's Best
    practices. They were new to Flash.

  • How to center loaded images?

    Hi,
    this really puzzles me... How onLoadInit and onLoadComplete
    listeners actually work? It is a photo slideshow, I am creating at
    runtime image holder and then centering its registration point to
    the center of main stage, then I am loading an image into it using
    MovieClipLoader class, then I need to change the image registration
    point so it is also centered on the stage. All works just
    excellently on my pc but unfortunately when on webserver the
    centering doesn't work! When the loading seems to be really
    intensive it doesn't care about onLoadInit listener!!! I test it at
    www.2sayhello.com/upgrade if anybody cares to see the effect.
    Thanks for any info
    Here is the code:

    I just got the idea that this problem may be related to
    loading more images at the same time, the problem occurs if I click
    on next or previous button in quick success, it forces to start
    downloading 2 or 3 images at the same time and that is exactly the
    moment I see not centered images or my preloader not finisshed.
    That may also means that onLoadInit or onLoadComplete were never
    executed... Each click on next or previus button creates and
    unloads image holder. Then it loads a new image into it by calling
    this function:

  • How to unload/load swf

    I have a Flash movie that automatically opens another Flash movie inside it. The main swf has a "Start" button at the bottom. When I click the Start button I want to unload the swf that loaded automatically (as a placeholder) and load a new Flash video swf. I'm doing this to create a placeholder for the video. I don't know what code I need to use on the button to unload the automatic swf and load the new swf video.

    if you don't need to stop any loaded streams (like sound/video), you can just reuse the same loader to load the next swf.  otherwise, apply unloadAndStop() to your loader before loading the next swf.

  • PLEASE HELP-HOW DOES A LOADED IPOD GET INTRODUCED TO A DIFFERENT COMPUTER

    without losing the music on it? What has to happen, how, and when does it have to happen. I sold my IPOD and the new owner does not want to lose any of the music. People have written in that it can be done and it cant be done? please help. Jeff

    I have found that the format that the ipod is originally introduced to is the only format that will recognize the ipod. So if you format your ipod on a mac when you first get it, only other mac computers will recognize it and not windows computers. However, if you introduced it to a windows computer first, the ipod can be recognized by any machine. This is what my previous experiences shows. If you want the ipod to be recognized by any computer, you must restore the ipod and format it to windows or whichever computer the owner has (this will result in the loss of music and other files). Sorry.
    Hope this Helps!

  • Get externallu loaded swf frame length?...

    Hi all,
    I need to know the frame length of a swf loaded via
    loadMovie().
    I want to stop the loaded swf playback before it reaches its
    last frame. So I need to extract
    (detect) the frame length of the swf, and call a function
    when the swf reaches the second to last frame.
    Is this possible?
    PS: I am not fluent in AS, so please provide some kind of
    code example if you can.
    seb (@webtrans1.com)
    high-end web design:
    http://webtrans1.com
    Sign-up for a free beta test of SiteLander, an ingenious
    website-builder:
    http://webtrans1.com/sitelander/
    music:
    http://myspace.com/popmodelberlin

    use the _totalframes property of your target movieclip (or
    _level).

  • Imported swfs getting data from main swf

    Hi everybody,
    I'm struggling shaking my old school AS2 mindset here. I've got a main swf which loads a bunch of subordinate swfs. I need my loaded swfs to see some variables in the main. For instance (example simplified for conversational purposes), let's say I've got a swf loading (we'll say littleSwf), which needs to set its rotation based on a variable (we'll say swfRotation) in the main. The rotation code is inside of the little swf. How does that little swf get told / find out what its rotation number is?
    How would I do that? I've tried everything I can think of and done some digging, but apparently not in the right places.
    Any input appreciated.
    Dan P.

    If you are loading the swf into another, chances are you are using a Loader.  So the Loader becomes the parent of the loaded swf.  And the main swf is the parent of the Loader.  So using the more common AS2 mindset, you would want to get any variable in the main swf by targetng the parent.parent... which in AS3 can be done using... MovieClip(parent.parent).
    A more OOP correct way of getting the rotation value to the child is to assign it to it from the main swf after it has completed loading the child.  To do this you assign a listener to the Loader to determine when the file has been loaded, and then you have the main file target the child thru Loader.content property.  You could then have some function in the child that the main calls and passes the rotation value to as an argument, or just have the main file perform the operation on the child using the rotation value if that is suitable.

  • Scrollpane all screwy  inside loaded swf

    I have had this problem using both the scrollPane component
    from Flash 8 and an open source code scrollpane that I found in
    Flashkit. I have an swf in which I'm using a scrollPane which works
    fine when I test the movie. However, I'm loading this swf into
    another master swf using loadMovie. When I do this, the scrollpane
    inside the loaded swf gets really buggy. First, the scrollbar will
    not stop scrolling when I release the mouse. Also, the whole
    scrollPane gets a green highlight around the edges (except in the
    open-source code scrollpane). HELP!! Does anyone know how to load a
    scrollPane into another swf without it getting all weird?

    //below is the code for the "slideshow.swf"
    //For the main movie.. I'm doing....
    button_btn.onRelease = function() {
    myMovieClipLoader_mc.loadMovie("slideshow.swf")//
    this.createEmptyMovieClip("container_mc",this.getNextHighestDepth());
    this.createEmptyMovieClip("buttons_mc",this.getNextHighestDepth());
    //loader//
    this.attachMovie("loader2","loader_mc",this.getNextHighestDepth());
    loader_mc._x = (Stage.width - loader_mc.width)/2;
    loader_mc._y = (Stage.height - loader_mc.height)/2;
    var myMCL:MovieClipLoader = new MovieClipLoader();
    var myListener:Object = new Object();
    myMCL.addListener(myListener);
    myListener.onLoadProgress =
    function(target,bytesLoaded,bytesTotal) {
    loader_mc._alpha = 100;
    var pct = Math.round(bytesLoaded/bytesTotal*100);
    loader_mc.bar_mc._xscale = pct
    myListener.onLoadComplete = function(target) {
    loader_mc._alpha = 0;
    //button movies//
    buttons_mc.attachMovie("prev","prev_mc",buttons_mc.getNextHighestDepth());
    buttons_mc.attachMovie("next","next_mc",buttons_mc.getNextHighestDepth());
    buttons_mc.next_mc._x = Stage.width -
    buttons_mc.next_mc._width;
    buttons_mc.next_mc._y = 10;
    buttons_mc.prev_mc._x = 10;
    buttons_mc.prev_mc._y = 10;
    //variables//
    var numPics:Number = 5
    var picArray:Array = new Array();
    var currentElement:Number = 0;
    for (i=0;i< numPics;i++) {
    var location:String = "pics/pic0" + (i+1) + ".jpg";
    picArray.push(location);
    myMCL.loadClip(picArray[currentElement],container_mc);
    //next button//
    buttons_mc.next_mc.onRelease = function() {
    if (currentElement < picArray.length-1) {
    currentElement++;
    else
    currentElement = 0;
    myMCL.loadClip(picArray[currentElement],container_mc);
    //prev button//
    buttons_mc.prev_mc.onRelease = function() {
    if (currentElement > 0) {
    currentElement--;
    else
    currentElement = picArray.length-1;
    myMCL.loadClip(picArray[currentElement],container_mc);
    }

  • Load swf directly into Captivate 5.5?

    Hello,
    How can I load swf files directly into Captivate 5.5 during runtime?
    I do not wish to have one single large Captivate file. Rather, I wish to create multiple small swf files and load them into Captivate as needed.
    I do this all the time in Flash, however,is this possible to load external swf into Captivate?
    Thank You
    iaustin

    You can select the option to externalise resources such as animations and widgets (both SWF files) in Project Preferences.

  • How to get correct coordinate & size of components in scaled swf

    I use canvas (I set it to fit whole screen size) to enclose a swfloader which loads a swf with width & height set to 100%. This swf has a movieclip. How can I get the correct coordinates of its position and its size after scaled in Flex?
    In the Flash CS4, the movielip has x=40, y=700. In Flex, the swf is scaled 100% but when I get the x value of this movieclip, it's still 40. I try to get the scale ratio of x-axis by refering to swf's scaleX. But its 1, weird enough.
    How can I get correct coordinates of movieclip?

    I do try the localToGlobal but it seems its 1:1 ratio, the codes I use:
    // swf is loaded by swfloader, there's a movieclip child named 'child_mc' in it, I want to locate its postion and size. It's top-left coordinates in flash cs4 is 4,740
    var swf_obj:MovieClip = MovieClip(swf.content);
    var mymc:MovieClip = swf_obj.child_mc;
    child_before:Point = new Point(mymc.x, mymc.y);
    child_after:Point = swf.localToGlobal(child_before);
    Alert.show(
         "before:"+child_before.x+","+child_before."y"+"\n"
         + "after:"+child_after.x+","+child_after."y"+"\n"
    the dump result is:
    before:4,740
    after:4,740
    dump screenshot is here: http://img198.imageshack.us/img198/2396/image2ew.png
    I use values of child_after to draw green box. The white box is child_mc's actual position after scaled to fit canvas size (in turn the screen size). You can see they are far from each other. Why?
    Do you mean I have to multiply the transform matrix myself to get the correct position?

Maybe you are looking for

  • Continual iTunes lock ups

    Hi there, Getting some odd behaviour over the past couple of weeks with 10.2 and now 10.2.1. To the best of my ability I am reckoning that it is being caused by a clash with iPhoto, let me explain further. I got a new iMac before Xmas and upgraded to

  • Am I getting a virus on my macbook pro?

    I think I'm getting a virus on my mac book pro that has been giving my a bunch of popup ads on youtube (other places too but im on youtube most often so its interfering) Here is what happened: I decided to try yify.tv for the first time - SKETCHY WEB

  • Images not showing up!! Running late... what else is new...

    I am using CS4 on a Mac I made a simple page with two images. Neither shows up when I upload the files. I have a site:      KathrynCecelia.com A folder for the site      kathryncecelia Inside that folder is a another folder      images Inside that fo

  • Imovie Crashes when copying project/event to external

    If I try and copy the project/ and event from within Imovie, Imovie crashes. If I copy them separately to external, it works. I'd like to do it together, as this way is too slow! This only happens on some projects, other copy without a hitch. I will

  • Which would be faster... Old Imac vs Mac Mini

    Maybe a stupid question but there you go , if so I apologise in advance . Which would be faster my aging iMac Intel Core Duo 2.16, or one of the new bread of Mac Minis .. primarily for photoshop and lightroom. Im trying to weigh up replacing the hard