转换位图数据

发布于 2024-08-14 02:21:38 字数 2855 浏览 4 评论 0原文

我正在尝试将多个 jpeg 图像动态 XML 加载到 fla 中的 bitmapdata 对象中。我可以在这个 .swf 文件的舞台上看到它们。

但是,我将其加载到另一个 .swf 中,这是我在单击菜单选项之一时调用的主要文件。

我收到这个错误: 错误 #1034:类型强制失败:无法将 com::Fashion@1daf4ca1 转换为 flash.display.MovieClip。

有谁知道如何转换吗?

private function initBitmapFile(file:String):void
    {
        loadBMP = new Loader();
        loadBMP.load(new URLRequest(file));
        loadBMP.contentLoaderInfo.addEventListener(Event.COMPLETE, handleLoadedBitmap);
    }



private function handleLoadedBitmap(event:Event):void
{
  bitmapData = Bitmap(LoaderInfo(event.target).content).bitmapData;
 }

    public function Fashion()
    {
        loadXML = new LoadXML(PHOTOFILE, handleLoadedPhotos);
    }   


    private function handleLoadedPhotos(event:Event):void
    {
        xmlItems = new XML(event.target.data);
        listItems = new ParseXML(xmlItems);
        var test:MovieClip = new MovieClip();

        var getListItems = listItems.getXMLListElements();

        for each (var item:XML in getListItems) {
            tabPhotos.push({ url:item.url });
        }

        for (var i:uint=0;i<tabPhotos.length;i++) {
            loadBitmap = new LoadBitmap(tabPhotos[i].url);
            addChild(loadBitmap);
        }
    }

menuOption.addEventListener(MouseEvent.CLICK, handleOptionClicked);
private function handleOptionClicked(event:MouseEvent):void
    {
        switch(event.target.name) {
            case "Fashion" : 
                loader.load(new URLRequest("fashion.swf"));
                break;
            case "Beauty" :
                loader.load(new URLRequest("beauty.swf"));
                break;
            case "Contact" :
                trace("Contact");
                break;      
        }

        // to know when next page is finished loading
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleFileLoaded);
    }

    private function handleFileLoaded(event:Event):void
    {
        // Contains the page we're going to display
        nextPage = event.target.content; // It crash Here!!!


        // If there's a current page, check when clicked on to next page is loaded 
        if (currentPage != null) {
            trace('Animate currentpage to disappear...');
            // Animate to dispappear the current page
            var tweenX = new Tween(currentPage, "x", Regular.easeOut, currentPage.x, 500, 1, true);
            var tweenAlpha = new Tween(currentPage, "alpha", Regular.easeOut, 1, 0, 1, true);

            tabTween.push(tweenX);
            tabTween.push(tweenAlpha);

            // Show the next page 
            tweenX.addEventListener(TweenEvent.MOTION_FINISH, currentPageGone);

        // If no current page, show and animate next page
        } else {
            trace('show next page')
            showNextPage();
        }


    }

I'm trying to load several jpeg images dynamically XML into bitmapdata object in fla. I can see them on the stage of this .swf file.

However, I load it into another .swf which is my main to call while clicking on one of menu option.

I got this error:
Error #1034: Type Coercion failed: cannot convert com::Fashion@1daf4ca1 to flash.display.MovieClip.

Does anyone know how to convert that??

private function initBitmapFile(file:String):void
    {
        loadBMP = new Loader();
        loadBMP.load(new URLRequest(file));
        loadBMP.contentLoaderInfo.addEventListener(Event.COMPLETE, handleLoadedBitmap);
    }



private function handleLoadedBitmap(event:Event):void
{
  bitmapData = Bitmap(LoaderInfo(event.target).content).bitmapData;
 }

    public function Fashion()
    {
        loadXML = new LoadXML(PHOTOFILE, handleLoadedPhotos);
    }   


    private function handleLoadedPhotos(event:Event):void
    {
        xmlItems = new XML(event.target.data);
        listItems = new ParseXML(xmlItems);
        var test:MovieClip = new MovieClip();

        var getListItems = listItems.getXMLListElements();

        for each (var item:XML in getListItems) {
            tabPhotos.push({ url:item.url });
        }

        for (var i:uint=0;i<tabPhotos.length;i++) {
            loadBitmap = new LoadBitmap(tabPhotos[i].url);
            addChild(loadBitmap);
        }
    }

menuOption.addEventListener(MouseEvent.CLICK, handleOptionClicked);
private function handleOptionClicked(event:MouseEvent):void
    {
        switch(event.target.name) {
            case "Fashion" : 
                loader.load(new URLRequest("fashion.swf"));
                break;
            case "Beauty" :
                loader.load(new URLRequest("beauty.swf"));
                break;
            case "Contact" :
                trace("Contact");
                break;      
        }

        // to know when next page is finished loading
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleFileLoaded);
    }

    private function handleFileLoaded(event:Event):void
    {
        // Contains the page we're going to display
        nextPage = event.target.content; // It crash Here!!!


        // If there's a current page, check when clicked on to next page is loaded 
        if (currentPage != null) {
            trace('Animate currentpage to disappear...');
            // Animate to dispappear the current page
            var tweenX = new Tween(currentPage, "x", Regular.easeOut, currentPage.x, 500, 1, true);
            var tweenAlpha = new Tween(currentPage, "alpha", Regular.easeOut, 1, 0, 1, true);

            tabTween.push(tweenX);
            tabTween.push(tweenAlpha);

            // Show the next page 
            tweenX.addEventListener(TweenEvent.MOTION_FINISH, currentPageGone);

        // If no current page, show and animate next page
        } else {
            trace('show next page')
            showNextPage();
        }


    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半仙 2024-08-21 02:21:38

“nextPage”是什么“类型”的对象?也许你可以尝试这种方式

 private function handleFileLoaded(event:Event):void {
     // Contains the page we're going to display
     // nextPage = event.target.content; // It crash Here!!!       

     var nextPage:DisplayObject = event.target.content as DisplayObject;
 }

只是一个想法,告诉我是否有帮助
干杯

What "type" of object is "nextPage" ? Maybe you can try this way

 private function handleFileLoaded(event:Event):void {
     // Contains the page we're going to display
     // nextPage = event.target.content; // It crash Here!!!       

     var nextPage:DisplayObject = event.target.content as DisplayObject;
 }

Just a thought, tell me if it helps
Cheers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文