Sign In  Sign Up Live-Chat

No name property on FlashBitmap class

Last post 12-03-2007, 5:28 AM by msfaiz. 2 replies.
Sort Posts: Previous Next
  •  11-29-2007, 1:51 PM 104574

    No name property on FlashBitmap class

    Hi,

    How am I supposed to find/reference an image in a swf file using it's instance name???? I would have thought the FlashBitmap class would had a property to do this, but it seems not. I'm starting to get a little fustrated to say the least trying at figure out something that should be simple. Someone please help before I pull out what little hair I have left. 

    Thanks,

    Richard

     
  •  12-03-2007, 1:40 AM 104890 in reply to 104574

    Re: No name property on FlashBitmap class

    I found out, you cannot assign instance name to the bitmap (image) object using Macromedia Flash 8. That is the reason, you cannot reference it using Aspose.Flash through its instance name. The workaround is that you should place your image as a symbol (Movie Clip), assign instance name to it using property inspector in Macromedia Flash and then search for the your movie clip via instance name using Aspose.Flash. Once you located your movie clip, you can delete it and then add a new movie clip with your new image.

    To see code example to reference objects by name, check this thread.

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


    Many Thanks and Kind Regards,

    Shakeel Faiz
    Support Engineer
    Aspose Tyumen Team
     
  •  12-03-2007, 5:28 AM 104915 in reply to 104574

    Re: No name property on FlashBitmap class

    Attachment: Present (inaccessible)

    Here is the code that replaces the image with new image.

    The code reads a source swf file namely sourcePictures.swf. This source file contains three images as movie clip with the name mov1, mov2 and mov3.

    Then the code looks for the PlaceObject2 tag corresponding to mov2. After finding it, it deletes this tag and adds a new image namely c:\image.jpg at the index of this tag.

    Finally, it writes the output presentation namely outPictures.swf

    I have attached the source and output swf files alongwith the code and image used to replace it. Please view them.

    CODE:

    *********************************************

    static void ReplaceImage()

    {

    FlashContainer flash = new FlashContainer("c:\\sourcePictures.swf");

    //Replace the second picture with new image

    PlaceObject2 placeObj=null;

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

    {

    if (obj.Name == "mov2")

    {

    placeObj = obj as PlaceObject2;

    break;

    }

    }

    //delete PlaceObject2 tag corresponding to this "mov2"

    int mov2Idx = 0;

    foreach (object obj in flash.Objects)

    {

    if(obj==placeObj)

    break;

    mov2Idx++;

    }

    flash.Objects.RemoveAt(mov2Idx);

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

    ArrayList flashObjs = AddImage(flash.NewIdentifier(), flash.NewIdentifier(), "c:\\image.jpg", 500, 500, 5000, 3000);

    //and add them at the index of deleted PlaceObject2 tag

    for(int i=0, j=mov2Idx ; i<flashObjs.Count; i++, j++)

    {

    flash.Objects.Insert(j, flashObjs[i]);

    }

    //Write the output swf on disk

    flash.Write("c:\\outPictures.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));

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

    return flashObjs;

    }


    Many Thanks and Kind Regards,

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