A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: AS3 & PHP - loading swf through PHP

  1. #1
    Member
    Join Date
    Aug 2003
    Posts
    70

    AS3 & PHP - loading swf through PHP

    Hi!

    I'd like to load a swf file through php from a Flash call, but it doesn't seem to work...

    My Flash code looks like:
    Actionscript Code:
    var localPath = "localhost path";
    var file:String = "MankSans";
    var fontLoader:Loader = new Loader();
    var fontLoaderInfo:LoaderInfo = fontLoader.contentLoaderInfo;
    fontLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressFontReg);  
    fontLoaderInfo.addEventListener(Event.COMPLETE, completeFunction);
    fontLoader.load(new URLRequest(localPath + "loadFont.php?f=" + file));

    function progressFontReg(e:ProgressEvent):void{
        trace("Loading font: " + (int(e.bytesLoaded/e.bytesTotal * 100)) + "%");
    }

    and my PHP code looks like:
    PHP Code:
    <?php
    $filename 
    $_GET['f'];

    ob_start();
    header("Expires: Mon, 20 Dec 1980 00:00:00 GMT");
    header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0"false);
    header("Pragma: no-cache");

    header("Content-Type: application/x-shockwave-flash");

    @
    readfile("fonts/" $filename .".swf");
    ob_end_flush();

    ?>

    Now, when I run the php file by itself (with a specified filename), it will return my swf file.
    When I load the PHP file through Flash, it will continue displaying:
    Loading font: 0%
    Loading font: 0%
    Loading font: 0%
    ...

    Any help is very much appreciated and welcome.

    Eddie
    Learning flash, one frame at a time

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Did you do
    addChild (fontLoader);

    or it will never load. Also you should check if your complete event is triggered. I recommend to send a message back to the movie, when the php file is executed, since the progressevent number is unreliable.
    Last edited by cancerinform; 01-13-2011 at 08:21 AM.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Member
    Join Date
    Aug 2003
    Posts
    70
    Thank you for your answer cancerinform.

    I've added addChild (fontLoader); but it doesn't do anything. I get the same behaviour.

    If you look at my PHP file you'll notice that all I'm returning is the actual swf. How could I also send the swf and also a message back to the movie?
    Learning flash, one frame at a time

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    I have tested your script by loading an image and it works. You can test by yourself:

    import flash.events.Event;
    import fl.controls.Button;

    var myBut:Button = new Button();
    myBut.move(150,150);
    addChild(myBut);
    myBut.addEventListener (MouseEvent.CLICK, ch);
    function ch (e:Event)
    {
    var localPath = "http://flashscript.biz/test/FK/";
    var file:String = "logo";
    var fontLoader:Loader = new Loader();
    var fontLoaderInfo:LoaderInfo = fontLoader.contentLoaderInfo;
    fontLoaderInfo.addEventListener (ProgressEvent.PROGRESS, progressFontReg);
    fontLoaderInfo.addEventListener(Event.COMPLETE, completeFunction);
    fontLoader.load (new URLRequest(localPath + "loadFont.php?f=" + file));
    addChild (fontLoader);
    }

    function progressFontReg (e:ProgressEvent):void
    {
    trace ("Loading font: " + (int(e.bytesLoaded/e.bytesTotal * 100)) + "%");
    }

    function completeFunction (e:Event):void
    {
    trace ("completed");
    }
    The trace gives always 0 but the file is loaded.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Member
    Join Date
    Aug 2003
    Posts
    70
    Thank you cancerinform. Weird progress response...

    As it seems it works for images, but doesn't want to work with swfs that have an embedded font in them.

    Basically I wanted to load an external swf that has an embeded font inside and access that. But anyway I tried to do it, I failed.

    If you can test it with loading an external swf that has an embedded font and then access that font from the main movie I would be forever grateful. Maybe I'm doing something wrong...
    Learning flash, one frame at a time

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    It would not work offline as a test file but only online in a browser:

    http://flashscript.biz/test/FK/LoadURLPHP.html

    This is the script I used:

    PHP Code:
    import flash.events.Event;
    import fl.controls.Button;
    import flash.text.TextField;
    import flash.text.TextFormat;

    var 
    myText:TextField = new TextField();
    myText.width 200;
    myText.height 100;
    myText.border true;
    myText.embedFonts true;
    addChild (myText);

    var 
    file:String "Chiller";
    var 
    myBut:Button = new Button();
    myBut.move (150,150);
    addChild (myBut);
    myBut.addEventListener (MouseEvent.CLICKch);
    function 
    ch (e:Event)
    {
        var 
    localPath "http://flashscript.biz/test/FK/";
        
        var 
    fontLoader:Loader = new Loader();
        var 
    fontLoaderInfo:LoaderInfo fontLoader.contentLoaderInfo;
        
    //fontLoaderInfo.addEventListener (ProgressEvent.PROGRESS, progressFontReg);
        
    fontLoaderInfo.addEventListener (Event.COMPLETEcompleteFunction);
        
    fontLoader.load (new URLRequest(localPath "loadFont.php?f=" file));
        
    addChild(fontLoader);
    }

    function 
    completeFunction (e:Event):void
    {
        
    trace ("completed");
        var 
    myFont:String file;
        var 
    tempTextFormat:TextFormat = new TextFormat();
        
    tempTextFormat.font myFont;
        
    tempTextFormat.size 36;
        
    myText.defaultTextFormat tempTextFormat;
        
    myText.appendText ("Hello World");

    Last edited by cancerinform; 01-14-2011 at 05:31 AM.
    - The right of the People to create Flash movies shall not be infringed. -

  7. #7
    Member
    Join Date
    Aug 2003
    Posts
    70
    I apologize for my late reply, but I'd like to thank you for your time, effort and example. I appreciate it.

    In the end I got the fonts to load a bit differently, but this is a great alternative in case the other solution I used will fail.

    Thank you!
    Learning flash, one frame at a time

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center