A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Error in phase of assigniment Action Script

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    15

    Error in phase of assigniment Action Script

    Hello Guys!
    I created the following action script named "sketch.as" :


    Code:
    package
    {
      
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import com.adobe.images.JPGEncoder;
    
    
    public class sketch extends Sprite {
    
    public function sketch():void {
    //this is your documentclass constructor
    }
    
    stage.addEventListener(MouseEvent.MOUSE_MOVE, moveCursor);
    Mouse.hide();
    
    function moveCursor(event:MouseEvent):void
    {
        pencil.x = event.stageX;
        pencil.y = event.stageY;
    }
    
    var canvas_mc:MovieClip = new MovieClip()
    addChildAt(canvas_mc, 0);
    canvas_mc.swapDepths
    function sketch()
    {
    
    canvas_mc.graphics.beginFill(0xFFFFFF);
    canvas_mc.graphics.drawRect(0, 0, 600, 500);
    canvas_mc.graphics.endFill();
    canvas_mc.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
    canvas_mc.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);
    canvas_mc.addEventListener(MouseEvent.MOUSE_MOVE, makeLine);
    }
    function startDrawing(event:MouseEvent):void{
    canvas_mc.graphics.lineStyle(1, 0, 1);
    canvas_mc.graphics.moveTo(mouseX, mouseY);
    canvas_mc.addEventListener(MouseEvent.MOUSE_MOVE, makeLine);
    }
    function stopDrawing(event:MouseEvent):void{
    canvas_mc.removeEventListener(MouseEvent.MOUSE_MOVE, makeLine);
    }
    function makeLine(event:MouseEvent):void{
    canvas_mc.graphics.lineTo(mouseX, mouseY);
    }
    sketch();
    
    
    var serverPath:String = "";
    function createJPG(m:MovieClip, q:Number, fileName:String)
    {
    var jpgSource:BitmapData = new BitmapData (m.width, m.height);
    jpgSource.draw(m);
    var jpgEncoder:JPGEncoder = new JPGEncoder(q);
    var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);
    var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");
    var jpgURLRequest:URLRequest = new URLRequest ( serverPath+"jpg_encoder_download.php?name=" + fileName + ".jpg");
    jpgURLRequest.requestHeaders.push(header);
    jpgURLRequest.method = URLRequestMethod.POST;
    jpgURLRequest.data = jpgStream;
    var jpgURLLoader:URLLoader = new URLLoader();
    //jpgURLLoader.load(jpgURLRequest);
    navigateToURL(jpgURLRequest, "_blank");
    }
    
    save_btn.addEventListener(MouseEvent.CLICK, saveBtnPress);
    save_btn.addEventListener(MouseEvent.ROLL_OVER, saveBtnOver);
    save_btn.addEventListener(MouseEvent.ROLL_OUT, saveBtnOut);
    
    function saveBtnPress(e:Event):void
    {
    createJPG(canvas_mc, 90, "sketch");
    }
    function saveBtnOver(e:Event):void
    {
    Mouse.show();
    pencil.visible = false;
    }
    function saveBtnOut(e:Event):void
    {
    Mouse.hide();
    pencil.visible = true;
    }
    
    
    }
    }
    Lately I created a file .fla in the same root of the file .as naming it "sketch.fla"

    When I try, in the Adobe Flash CS4 Professional screen, to assign to ".fla" in the properties Publish my action script, the following message appears:

    “A definition for the document class could not be found in the classpath, so one will be automatically generated in tha SWF file upon export.”

    Obviously, it doesn’t function
    Could somebody help me??

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You need to set the document class to "sketch". Once you do that, you'll need to fix the sketch class, which is severely broken.

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Now that I'm back from lunch, let me tell you a bit more about how sketch is "severely broken".

    First, it should be Sketch, with a capital S. Classes should begin with an uppercase letter, variables with lowercase.

    I have to give you credit for extending Sprite rather than MovieClip. Good job there.

    All code in your classes should be either 1: a method or 2: a variable declaration. You cannot have code just sitting out there outside of methods and expect it to do the right things. (Actually, that code is executed when the class is loaded, in a static context. You CAN use that, but your code doesn't work there.)

    There is no swapDepths method. And even if there were, you'd need to call it as a method and in a function context.

    You cannot have multiple methods with the same name (you have two "sketch" methods). All your methods should be declared to be in a namespace such as private, protected, or public. All methods other than the constructor should declare a return type.

    You should be sure to format your code so that it's obvious what is nested inside of what.
    Last edited by 5TonsOfFlax; 01-06-2011 at 03:41 PM.

  4. #4
    Junior Member
    Join Date
    Jan 2011
    Posts
    15
    ok, thanks ... but this code, in a another file .fla, works correctly.
    The error is in the association between .as and .fla file.

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    That code looks like you took a bunch of frame script and pasted it into the body of a class. It doesn't work that way. You have to make the changes I said above.

    Your FIRST problem is the association between .as and .fla. Once you fix that, you'll run into the problems caused by the code in the .as.

    Once again, to fix it, you need to set the Document Class property of your fla.

  6. #6
    Junior Member
    Join Date
    Jan 2011
    Posts
    15
    The message appears when I insert the name of my class in the properties panel on the top on the right in the text area.

    I tried also to set the classpath by hand with the path in which the file .as is contained on my desktop.

  7. #7
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You aren't being very clear. This is what you said originally:
    I try, in the Adobe Flash CS4 Professional screen, to assign to ".fla" in the properties Publish my action script,
    I have no idea what property you are setting to what value.

    Are you in fact setting the "Document Class" property to "sketch"?

    Is your file actually "sketch.as" and not say "Sketch.as"? Capitalization must match the actual name of your class (by convention, both would start with a capital, and you'd use "Sketch" for the Document Class as well).

    By default, the classpath includes ".", which is the current directory. If you've messed with the classpath, make sure that it still includes that. Also make sure that the .as and .fla are in the same directory.

    The error message you are seeing means that for some reason flash does not find your .as file when trying to compile. But I think you already knew that.

  8. #8
    Junior Member
    Join Date
    Jan 2011
    Posts
    15
    Yes, i set Document Class with : sketch.as and my file is "sketch.as"
    And my classpath includes :

    "."
    "C:\ ecc ecc" <--- path of directory with file "sketch.as"

  9. #9
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The Document Class should be set to "sketch", not "sketch.as"

  10. #10
    Junior Member
    Join Date
    Jan 2011
    Posts
    15
    OH YES !!!
    Great

    And now ... i correct the code

    Thanks so much !

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