Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
Old 02-08-2008, 06:23 PM   #1
eliddell
Senior Member
 
eliddell's Avatar
 
Join Date: Sep 2006
Location: boston
Posts: 327
Send a message via AIM to eliddell
Angry TypeError: Error #1034: Type Coercion failed: cannot convert []@2ab1b69 to ATIscripts

I am getting so frustrated..

i was getting a different error.. now i am getting this error and i didn't even change anything.. what does this error mean? how do i read these things?

erik

TypeError: Error #1034: Type Coercion failed: cannot convert []@2ab1b69 to ATIscripts.printMovie.
at printTest_fla::MainTimeline/frame1()


my as file
ActionScript Code:
package ATIscripts {     import flash.printing.PrintJob;     import flash.printing.PrintJobOrientation;     import flash.display.Stage;     import flash.display.MovieClip;     import flash.text.TextField;     import flash.geom.Rectangle;     public class printMovie extends MovieClip {         public function printMovie(slides:Array) {             var my_pj:PrintJob = new PrintJob();             if (my_pj.start()) {                     var i:Number;                     for(i=0;i<slides.length;i++){                     trace(slides[i][0]);                     trace(slides[i][1]);                     trace("------------");                     }                                 }         }     } }

my fla script
ActionScript Code:
import ATIscripts.printMovie var slides:Array = new Array(["mov","1"],                              ["mov2","34"]                              ) printMovie(slides);
eliddell is offline   Reply With Quote
Old 02-08-2008, 07:15 PM   #2
hardyvoje
Registered User
 
hardyvoje's Avatar
 
Join Date: Aug 2005
Posts: 77
Default

HEY!

You have to instantiate object from class to access its methods or create static class


so 2 solutions:
1. in FLa add:

var myPrinterrintMovie = new printMovie();
myPrinter.printArray(slides);

and add rename constructor function to printArray()

it's better in my opinion to separate instantation and execution, bacause you'll may be use same instance to print something else.

2. in Class definition

rename function to printArray() and set

public static function printArray(slides:Array) {
hardyvoje is offline   Reply With Quote
Old 02-08-2008, 09:57 PM   #3
Slowburn
[Invent:Design:Create]
 
Join Date: Sep 2002
Location: Toronto, ON
Posts: 2,068
Default

ActionScript Code:
package ATIscripts {     import flash.display.MovieClip;     import flash.printing.PrintJob;             public class Printer extends MovieClip     {                 public function Printer():void         {             super();         }                 public function printSlides( slides:Array ):void         {             var pntJob:PrintJob = new PrintJob();             if( pntJob.start() )             {                 for( var i:int = 0; i < slides.length; i++ )                 {                     for( var j:int = 0; j < slides[i].length; j++ )                     {                         trace( slides[i][j] );                     }                     trace( "--------" );                 }             }         }     } } var slides:Array = new Array( ["mov", "1"], ["mov2", "34"] ); var printer:Printer = new Printer(); addChild( printer ); printer.printSlides( slides );
__________________
o Please do a search before you post
o Please use the [ as][ /as] tag for your code (so we can read it clearly)
Slowburn is offline   Reply With Quote
Old 02-08-2008, 11:11 PM   #4
hardyvoje
Registered User
 
hardyvoje's Avatar
 
Join Date: Aug 2005
Posts: 77
Default

just suggestion: no need to addChild(printer);
hardyvoje is offline   Reply With Quote
Old 02-09-2008, 10:34 PM   #5
airwin
Registered User
 
Join Date: Feb 2008
Posts: 5
Default

i have the same error message for my code but i don't understand what "You have to instantiate object from class to access its methods or create static class" means.

package go.boardview
{
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.*;
import flash.geom.Point;
import flash.display.DisplayObject;
import go.model.*;

public class BoardView extends MovieClip

{
var r:StoneView;
private var stoneArray:Array = new Array();

public function BoardView():void
{
setStone();
}
public function setStone():void
{
for(var i = 0; i < 19; i++)
{
for(var a = 0; a < 19; a++)
{
var oneStone:StoneView = new StoneView();
oneStone.setLocation(i,a);
oneStone.setColor(StoneValue.NONE);
oneStone.addEventListener(MouseEvent.CLICK, stoneClicked);
stoneArray.push(oneStone);
oneStone.x = 32 + (15*i);
oneStone.y = 20 + (15*a);
addChild(oneStone);
}
}

}

private function stoneClicked(e:MouseEvent):void
{
var pickedStone:StoneView = StoneView(e.target);

}


}
}
airwin is offline   Reply With Quote
Old 02-09-2008, 10:38 PM   #6
airwin
Registered User
 
Join Date: Feb 2008
Posts: 5
Default

sorry my code didn't format into the actionscript file format...
airwin is offline   Reply With Quote
Old 02-10-2008, 08:09 AM   #7
sgartner
Senior Member
 
Join Date: Jan 2008
Location: Boise, ID
Posts: 227
Default

Quote:
Originally Posted by airwin View Post
i have the same error message for my code but i don't understand what "You have to instantiate object from class to access its methods or create static class" means.

ActionScript Code:
package go.boardview {     import flash.display.MovieClip;     import flash.display.SimpleButton;     import flash.events.*;     import flash.geom.Point;     import flash.display.DisplayObject;     import go.model.*;         public class BoardView extends MovieClip     {         var r:StoneView;         private var stoneArray:Array = new Array();                 public function BoardView():void         {             setStone();         }         public function setStone():void         {                 for(var i = 0; i < 19; i++)                 {                        for(var a = 0; a < 19; a++)                     {                         var oneStone:StoneView = new StoneView();                         oneStone.setLocation(i,a);                         oneStone.setColor(StoneValue.NONE);                         oneStone.addEventListener(MouseEvent.CLICK, stoneClicked);                         stoneArray.push(oneStone);                         oneStone.x = 32 + (15*i);                          oneStone.y = 20 + (15*a);                         addChild(oneStone);                     }                 }                                            }                 private function stoneClicked(e:MouseEvent):void         {             var pickedStone:StoneView = StoneView(e.target);                     }                            } }
What Hardyvoje was saying is that the original poster appeared to be confused about how to use a class (I would also say that the defined class is not Object Oriented either).

It is unfortunate that ActionScript decided to use "CLASS(variable)" as the syntax for coercion (or casting as other languages call it) instead of "(CLASS)variable" which I believe would have been less confusing.

So when eliddell did this:

ActionScript Code:
import ATIscripts.printMovie; var slides:Array = new Array(["mov","1"],                                        ["mov2","34"]); printMovie(slides);

Eliddell clearly thought he was calling the constructor for the class printMovie, but how ActionScript saw it was that he was trying to change the type of "slides" to the type "printMovie". Clearly this is not a reasonable translation.

Now, from your code above, you have a similar line of code, but in your case you really are casting the event object into an object of the type StoneView, which as I see it shouldn't be a problem. So, first I would say that we need to see your actual error message and maybe if you included StoneView I might be able to see the problem, or maybe after this description you will be able to see it yourself.
sgartner is offline   Reply With Quote
Old 02-10-2008, 08:15 AM   #8
sgartner
Senior Member
 
Join Date: Jan 2008
Location: Boise, ID
Posts: 227
Default

Quote:
Originally Posted by Slowburn View Post
ActionScript Code:
package ATIscripts {     import flash.display.MovieClip;     import flash.printing.PrintJob;             public class Printer extends MovieClip     {                 public function Printer():void         {             super();         }                 public function printSlides( slides:Array ):void         {             var pntJob:PrintJob = new PrintJob();             if( pntJob.start() )             {                 for( var i:int = 0; i < slides.length; i++ )                 {                     for( var j:int = 0; j < slides[i].length; j++ )                     {                         trace( slides[i][j] );                     }                     trace( "--------" );                 }             }         }     } } var slides:Array = new Array( ["mov", "1"], ["mov2", "34"] ); var printer:Printer = new Printer(); addChild( printer ); printer.printSlides( slides );
Slowburn,

Yes, you fixed his syntax, but the real problem is that printSlides is not a member function of the class printer, it is simply a function and so shouldn't really be part of a made-up class just to make it work:

ActionScript Code:
import flash.display.MovieClip; import flash.printing.PrintJob; function printSlides (slides:Array) : void   {       var pntJob:PrintJob = new PrintJob();       if (pntJob.start())         {           for (var i:int = 0; i < slides.length; i++)             {               for (var j:int = 0; j < slides[i].length; j++)                 {                   trace(slides[i][j]);                 }               trace("--------");             }         }   } var slides:Array = new Array( ["mov", "1"], ["mov2", "34"] ); printSlides(slides);
sgartner is offline   Reply With Quote
Old 02-10-2008, 07:11 PM   #9
airwin
Registered User
 
Join Date: Feb 2008
Posts: 5
Default

this is StoneView. i'm very new at this and trying to understand the appropriate vocabulary for everything, so i hope this is accurate (or at least comprehensible).

i don't understand in the original code i posted what the goal of 'e.target' - that is, i'm not certain exactly what that does in the code...but i realize that i'm calling StoneView and passing through the parameter 'e.target' without declaring a type in the StoneView constructor. i think i'm supposed to give a type in the constructor? is that correct? but what type is target?



PHP Code:
package go.boardview {
    
import flash.display.MovieClip;
    
import flash.display.SimpleButton;
    
import flash.events.*;
    
import go.model.*;
    public class 
StoneView extends MovieClip
    
{
        private var 
boardXint;
        private var 
boardYint;
        
        public function 
StoneView():void // ADD TO THE CONSTRUCTOR TO LINK WITH BOARDVIEW
        
{
            
        }
        
        
        public function 
setLocation(newX:intnewY:int):void
        
{
            
boardX newX;
            
boardY newY;
        }

            
            
        public function 
setColor(color:StoneValue):void
        
{
            if (
color == StoneValue.BLACK)
            {
                
gotoAndStop("black");
            }
        
            else if (
color == StoneValue.WHITE)
            {
                
gotoAndStop("white");
            }
            else 
            {
                
gotoAndStop("none");
            }
                
        }

        public function 
getLocation():void // write out 
        
{
        }
    }

airwin is offline   Reply With Quote
Old 02-10-2008, 07:47 PM   #10
airwin
Registered User
 
Join Date: Feb 2008
Posts: 5
Default

also, this is my error message.

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::SimpleButton@343b091 to go.boardview.StoneView.
at go.boardview::BoardView/::stoneClicked()
airwin is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Interface & Type Coercion failure jaga ActionScript 3.0 1 01-23-2008 09:51 PM
unable to convert XML string to Number data type jimboyes ActionScript 2.0 4 06-07-2007 10:01 PM
How would one convert a variable of type STRING to an OBJECT lowRider ActionScript 2.0 2 03-06-2007 09:15 PM
Setting data type of an object at run time J. Grady Broyles ActionScript 2.0 8 01-08-2007 11:06 PM
How to convert variable type STRING to MOVIE CLIP (aka monkey cloning) enfant2soleil ActionScript 2.0 4 07-21-2005 09:27 AM


All times are GMT. The time now is 06:38 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.