A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Use ActionScript 3.0 to output edited SWF

  1. #1
    Junior Member
    Join Date
    Nov 2008
    Posts
    14

    Smile Use ActionScript 3.0 to output edited SWF

    Hi guys, this is the first time I post in our forum, I would like to say thanks to whom reading this.

    I'm new to ASv3 and in stuck of dealing with a problem like this :

    I have some .fla file with text/image in it, say, it was a text of "I love U", and a picture of a heart, now I need to make some ActionScript embedded in the .fla file, then compile to a SWF file, say "valentine.swf"

    All I want, is that actionscript embedded in the SWF would make the SWF accepts some parameters I would pass to it like "valentine.swf?image=Chocolate.jpg&text=Happy Valentine", and then either save the SWF itself with the changes I made ( change the text and picture ), so that next time when I open it without any parameters it would display Chocolate.jpg as background and a text of "Happy Valentine"; or, make another SWF with the change I made ( the coordinates of components stay still only contents changed) ( still using that actionscript and some-whatever-programming-language like php,.net,java or something ).

    After banging my head against the wall several times for the last whole week, I'm now just pray for someone who would point me out that this is not possible at all, or shed some light, tell me how would it be done or your opinion of how things should be deal with.

    I would be much appreciate if you are still read at this point. Thanks in advance for all who read. Have a nice day. Peace & out.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    It's somewhat possible, but very misguided. You /could/ generate a bytearray with an edited swf, but you couldn't save it without some server side component.

    It's a bit like asking "I drove my car into my garage and parked it. How do I take it apart to put it back together facing the other way so I can drive out?" Don't. Why not put it in reverse?

    You can grab the parameters such as "image=Chocolate.jpg" through the loaderInfo.parameters object. Search this forum for "flashvars" to get a better explanation.

    If you don't want to always pass those parameters, you could store the last chosen state into a SharedObject and load that back up when the swf loads. This doesn't allow you to then send the swf with state to someone else though since they won't have your SharedObject.

  3. #3
    Junior Member
    Join Date
    Nov 2008
    Posts
    14

    Smile Translated into details...

    Hi Flax,

    First, thank you for your fast reply, you lightned up me a bit....

    The problem I described maybe somehow misguided, so I would describe it in details here :

    - I have a .fla file, which already have a text "I love U" and an image of a heart as background ( made by import jpg to stage, and use text tool ).

    - I would make a actionscript file ( .as ) then embed to the .fla file

    - I read about actionscript 3, all visual components are child of display list, but how could I map ( aka reference ) to the image and text which already existed in the .fla file ( in this case the text "I love U", and the background image ) then add it to display list ( with a reference ) for later use ?

    - After I embeded a .as into .fla file, I publish to a SWF file

    - Is that possible that the SWF would save it self if I try to pass to it some parameters like "valentine.swf?image=Chocolate.jpg&text=Happy Valentine" or with some help of server-side script like php, I would save to another SWF that would store the Chocolate.jpg as background and the Happy Valentine as text with appropriate coordinate like the first SWF

    Here is somecode I made to dynamic load some text/image into a flash ( just a demo ), but cant save the SWF with the picture inside it, and it need a JPG along with the SWF, I just want single file SWF.

    Here the code :

    package {

    import flash.display.Sprite;
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.display.LoaderInfo;
    import flash.text.TextField;

    public class Main extends Sprite {
    public function Main() {
    //Create new Loader
    var loader:Loader = new Loader();
    //Add loader to Display List
    addChild(loader);
    //Check result String
    var resultStringImage:String = getSWFParam("image","defaultString");
    if (resultStringImage == "defaultString") {
    loader.load(new URLRequest("sunset.jpg"));
    } else {
    loader.load(new URLRequest(resultStringImage));
    }
    var field:TextField = new TextField();
    addChild(field);
    var resultStringText:String = getSWFParam("text","defaultString");
    if (resultStringImage == "defaultString") {
    field.text = "DefaultString <NO PARAMS PASSED> !";
    } else {
    field.text = resultStringText;
    }
    }

    protected function getSWFParam(name:String, defaultValue:String):String {
    var paramObj:Object = LoaderInfo(stage.loaderInfo).parameters;
    if ((paramObj[name] != null) && (paramObj[name] != "")) {
    return paramObj[name];
    } else {
    return defaultValue;
    }
    }
    }
    }


    Thanks for reading, I read some of your FlashVars topic/answers too, mostly useful informations, is there a "Thank" button for useful post in our forum ??

    Best Regards.

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I don't think you're going to find a solution which ends up with a single swf and no external assets.

    If you wanted, you could export a graphic from your swf so that you have a jpg or png of your background and text. Would that accomplish what you want?

  5. #5
    Junior Member
    Join Date
    Nov 2008
    Posts
    14

    Smile Thanks :D

    Yeah, maybe you just tell me the answer I need, I really think that would not possible to find some solutions which would end up with single SWF and no external assests.

    I read from some topic with the tag of "Flex Cookbook" that mentioned to use AS in AIR application to export graphic to SWF, at this link : http://www.adobe.com/cfusion/communi...=2&postId=9364 and some information of outputing to SWF by PHP at this link : http://www.ibm.com/developerworks/xm...ash/index.html. So is it possible to mix up these techs with outputing graphic of SWF ? I think still impossible coz of graphic export out of SWF would be a combine image of text + background image ==> I still wanna have single SWF and still got controll of these components like the first SWF at the end.

    But, anyway, thanks again, before coming to this topic, I m pretty clueless, now at least I would stop banging head against the wall. Your da best, Flax.

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I think it's important to determine whether you need a swf at all. Does the produced swf have to be interactive? Animated? If all it is is a static background with some text on it, then you can produce a png of that combined image instead of a swf.

    The links you posted are interesting. The first one is AIR only, which is fine if that works for you, but if it needs to be online, that won't help. The second one looks very outdated, and I don't know enough about ming or php to comment on it.

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