Sign In  Sign Up Live-Chat

How to update an image in an swf?

Last post 12-01-2008, 6:19 PM by msfaiz. 10 replies.
Sort Posts: Previous Next
  •  11-29-2007, 10:53 AM 104535

    How to update an image in an swf?

    Hi,

    I have a swf with an image which is a movie clip. This movie clip instance is named imageTag.  I was wondering how to access this in my aspx page and change the image to something the user uploads to the server? I have gone through the "Displaying Image Using Aspose.Flash" documentation but there is no documentation on how to access and update images in swf's.  I was wondering if someone can help me or point me to some code sample?

    Thanks in advance for any help given.
    Masterson

     
  •  11-30-2007, 1:28 AM 104647 in reply to 104535

    Re: How to update an image in an swf?

    Dear Masterson,

    I will provide you code example after experimenting few things. It will be good if you provide me your sample swf file but not required


    Many Thanks and Kind Regards,

    Shakeel Faiz
    Support Engineer
    Aspose Tyumen Team
     
  •  12-03-2007, 5:57 AM 104922 in reply to 104535

    Re: How to update an image in an swf?

    I have given the code example to replace image in another thread at this link.

    http://www.aspose.com/Community/Forums/thread/104574.aspx 


    Many Thanks and Kind Regards,

    Shakeel Faiz
    Support Engineer
    Aspose Tyumen Team
     
  •  12-05-2007, 5:46 AM 105246 in reply to 104922

    Re: How to update an image in an swf?

    Hi Msfaiz,

    Thank you for your reply. I have tried out the code and it works but not to the desired effect that I want. It does remove the image and replaces it, but it also loses all the properties and effects of the image previous image. For example if I have an animation(e.g. fade in and out) when I replace the image I wish to keep the animation.

    Also is there a way to find out the x and y position of a movieclip in flash? and are you able to find movie clips(with instance name) nested within other movie clips(with instance name), because when loop through the flash I can only see named instance in the root level and nothing deeper.

    Thanks again for your help.
    Masterson

     
  •  12-07-2007, 5:25 AM 105596 in reply to 105246

    Re: How to update an image in an swf?

    Dear Masterson,

    Can you please provide me some sample swf, so that I could see after effects of replacing the image with my approach? According to my findings, when you assign instance name to some object e.g movie clip, you can find its reference from FlashContainer.Objects collection. You will need to iterate all the PlaceObject2 objects and check their name property, it will be the instance name assigned earlier by you. In my code example, I iterate the PlaceObject2 tags and find the reference of movie clips named mov1 in this way.


    Many Thanks and Kind Regards,

    Shakeel Faiz
    Support Engineer
    Aspose Tyumen Team
     
  •  12-07-2007, 6:12 AM 105601 in reply to 105596

    Re: How to update an image in an swf?

    Attachment: Present (inaccessible)

    Hi msfaiz,

    Here is my fla file.  If you look there is a movie clip named ImageTag and inside that movie clip is another movie clip named ImageTagInner.  What I would like to do is place an image dynamically inside this clip and retain the animation.

    Thanks again for your help
    Masterson

     
  •  12-10-2007, 8:25 AM 105751 in reply to 105601

    Re: How to update an image in an swf?

    Attachment: Present (inaccessible)

    Dear Masterson,

    Just to update you, the following code finds the reference to InnerImageTag object. First it finds the PlaceObject2 tag whose name property matches to ImageTag, having found it, the code looks for its DefineSprite. This DefineSprite is actually the movie clip which contains InnerImageTag inside its controls collection.

    FlashContainer flash = new FlashContainer("c:\\Untitled-1.swf");

    //Find the placeobject2 tag

    PlaceObject2 placeobjImageTag=null;

    foreach (PlaceObject2 obj in flash.GetObjectsOfType(BaseObjectType.PlaceObject2))

    {

    if (obj.Name == "ImageTag")

    {

    placeobjImageTag = obj;

    break;

    }

    }

     

    //Find the definesprite corresponding to placeobject2 found above

    DefineSprite defsprtImageTag=null;

    foreach (DefineSprite obj in flash.GetObjectsOfType(BaseObjectType.DefineSprite))

    {

    if (obj.SpriteId == placeobjImageTag.ObjectId)

    {

    defsprtImageTag = obj;

    break;

    }

    }

    //Now search for innerImageTag in the definesprite tag found above

    PlaceObject2 placeobjInnerImageTag = null;

    foreach (PlaceObject2 obj in defsprtImageTag.ControlTags)

    {

    if (obj.Name == "InnerImageTag")

    {

    placeobjInnerImageTag = obj;

    break;

    }

    }


    Many Thanks and Kind Regards,

    Shakeel Faiz
    Support Engineer
    Aspose Tyumen Team
     
  •  12-11-2007, 5:40 AM 105852 in reply to 105751

    Re: How to update an image in an swf?

    Hi Shakeel,

    Thanks for the code to find the inner movie. This is great but I can't replace the image. Even with the code from this post

    http://www.aspose.com/Community/Forums/thread/104574.aspx 

     
  •  12-13-2007, 2:49 PM 106185 in reply to 105852

    Re: How to update an image in an swf?

    Attachment: Present (inaccessible)

    Dear Masterson,

     

    Finally, I have inserted the image into your movie clip (sprite).  I have attached these three files

     

    Source Image

    image.jpg

     

    Source SWF File

    Untitled-1.swf

     

    Output SWF File

    out.swf

     

    I have also attached the code in a text file. You can also see this code below.

     

    I assume you understand AddImage() method, which I gave you earlier, this time I have done a little modification inside it, instead of adding a Placeobject2 in ArrayList at the very last line of code, I have removed it,  I mean these lines

     

    /Comment this line, we don't need to place the shape which contains our

    //image in this PlaceObject2 tag, we will add it in our movie clip

    //InnerImageTag PlaceObject2

    //flashObjs.Add(new PlaceObject2(shpID, 1, 0, 0));

     

    instead I add the shape object which contains the image inside your InnerImageTag PlaceObject2 tag.  I mean this line

     

    //now change the object id of the innerImageTag

    placeobjInnerImageTag.ObjectId = shpID;

     

    And here is code. I hope, you understand it and it will be really helpful for you.

     

    Code

    ---------------------------------------------------------------------------------

    static void Main(string[] args)

    {

    FlashContainer flash = new FlashContainer(@"d:\downloads\Untitled-1.swf");

    //Find the placeobject2 tag

    PlaceObject2 placeobjImageTag = null;

    foreach (PlaceObject2 obj in flash.GetObjectsOfType(BaseObjectType.PlaceObject2))

    {

    if (obj.Name == "ImageTag")

    {

    placeobjImageTag = obj;

    break;

    }

    }

     

    //Find the definesprite corresponding to placeobject2 found above

    DefineSprite defsprtImageTag = null;

    foreach (DefineSprite obj in flash.GetObjectsOfType(BaseObjectType.DefineSprite))

    {

    if (obj.SpriteId == placeobjImageTag.ObjectId)

    {

    defsprtImageTag = obj;

    break;

    }

    }

    //Now search for innerImageTag in the definesprite tag found above

    PlaceObject2 placeobjInnerImageTag = null;

    foreach (PlaceObject2 obj in defsprtImageTag.ControlTags)

    {

    if (obj.Name == "InnerImageTag")

    {

    placeobjInnerImageTag = obj;

    break;

    }

    }

    //Get all the objects needed for adding image in swf file

    int imgID = flash.NewIdentifier();

    int shpID = flash.NewIdentifier();

    ArrayList flashObjs = AddImage(imgID, shpID, "c:\\image.jpg", 0, 0, 1000, 1000);

    //insert these objects before sprite

    int spriteIdx = flash.Objects.IndexOf(defsprtImageTag);

    //and add them in flash file

    foreach (object obj in flashObjs)

    {

    flash.Objects.Insert(spriteIdx++, obj);

    }

    //now change the object id of the innerImageTag

    placeobjInnerImageTag.ObjectId = shpID;

    flash.Write(@"c:\out.swf");

    }

    static ArrayList AddImage(int imgID, int shpID, string imageFile, int X, int Y, int Width, int Height)

    {

    ArrayList flashObjs = new ArrayList();

    //int imgID = flash.NewIdentifier();

    FlashBitmap bmp = new FlashBitmap(imgID, FlashBitmapType.FlashBitmapJpeg, false, imageFile);

    flashObjs.Add(bmp);

    //Calculate scaling factor

    double scaleX = ((double)Width) / (double)bmp.Width;

    double scaleY = ((double)Height) / (double)bmp.Height;

    //Create a rectangle shape with image as a fill via ShapeManager

    ShapeManager shapeManager = new ShapeManager();

    shapeManager.Add(new SolidLine(1, new RGB(255, 0, 0, 255)));

    shapeManager.Add(new BitmapFill(FillStyleType.NonSmoothedClippedBitmap, imgID, new MatrixTransform(X, Y, scaleX, scaleY)));

    shapeManager.DrawRectangle(X, Y, Width, Height);

    //int identifier = flash.NewIdentifier();

    //int depth = 1;

    //Add the shape and place it on display list

    flashObjs.Add(shapeManager.GetDefineShape(shpID));

    //Comment this line, we don't need to place the shape which contains our

    //image in this PlaceObject2 tag, we will add it in our movie clip

    //InnerImageTag PlaceObject2

    //flashObjs.Add(new PlaceObject2(shpID, 1, 0, 0));

    return flashObjs;

    }

     


    Many Thanks and Kind Regards,

    Shakeel Faiz
    Support Engineer
    Aspose Tyumen Team
     
  •  11-30-2008, 9:20 AM 154642 in reply to 106185

    Re: How to update an image in an swf?

    hi msfaiz,

    I m trying to do the same as masterson001 but my backend is in java. So, is there any library wich I can apply to update image inside a swf? Or perhaps some actionscript 3 code that I can use to do that? Both solution, be java or actionscript attend me very well.

    Thanks
     
  •  12-01-2008, 6:19 PM 154825 in reply to 154642

    Re: How to update an image in an swf?

    Hi,

     

    I have implemented the above task with Aspose.Flash which is unfortunately not in JAVA. But I think, you can find JAVA library or actionscript code on the internet.


    Many Thanks and Kind Regards,

    Shakeel Faiz
    Support Engineer
    Aspose Tyumen Team
     
View as RSS news feed in XML