The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Page 2 of 4 FirstFirst 1234 LastLast
Results 16 to 30 of 49

Thread: Infrequently Asked Questions and Other Interesting Threads

  1. #16
    TheCanadian's Avatar
    10,305
    posts
    Noo doot aboot it, eh?

    Why does my preloader not appear for a while then start at an insanely high number?

    There are two possible causes to this:

    1) Your preloader itself takes up an insane size in your movie. If it's, for example, 50% of the total size of your movie then by the time it is loaded and displays on the stage your movie will be half loaded. You can have Flash generate a size report when you publish your movie so you can see how the bytes of your movie are distributed between frames. In the Publish Settings:


    2) You have a lot of movie clips and AS2 classes exported for the first frame. When Flash compiles your movie, it removes all unused symbols from the library to reduce file size. That is, any symbols not placed on the timeline at some point in your movie are removed. However, the compiler has no way to tell which symbols are used in the AS of your movie. This is why, when setting up a linkage ID for your movie clips, you must check export for first frame so that the compiler will know that you want to use the symbols in AS and consequently will not remove them during it's optimization. And that is what gums up the works. All of those symbols must be loaded before the first frame which means that your preloader cannot display until they have finished.

    The solution is not to export them for the first frame. But to prevent them from being removed at compile time you must have them appear somewhere on the timeline of your movie. Having all of the symbols used in AS one frame after your preloader is sufficent to be able to use them in the rest of your movie. Then when the movie is loaded, skip this frame to the beginning of your movie:


    AS2 classes are another part of this problem since they are also exported before the first frame. This can be changed very easily however in the AS settings dialogue:


    Note that if you export the classes to a frame later than any symbols using them, those symbols will fail to work correctly.

    For more info, here is a very comprhensive preloading tutorial by senocular:
    http://www.senocular.com/flash/tutorials/preloading/
    Last edited by TheCanadian; January 8th, 2007 at 03:23 PM.
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  2. #17
    phorte's Avatar
    760
    posts
    formerly aussie devil
    Embeded fonts should be in here i reckon. That question comes up so much around here.

    Also, nice work on the latest topics. Keep up the good work!

  3. #18
    Make sure to mention the pixelation problem…


    K-Emmys-06: Best Footer; and K-Emmys-06: Most Active Member

  4. #19
    TheCanadian's Avatar
    10,305
    posts
    Noo doot aboot it, eh?

    Why can't I add properties to a class?

    The Problem
    When trying to add properties to a class, the compiler gives an error saying that there is no such property:
    Code:
    Math.myMethod = function():Void {} //error
    The Answer
    The problem here is with how the class is defined and is more of a thing you'll have to accept rather than fix. A class can be either dynamic or non-dynamic. Dynamic classes can have properties added to them outside of the class definition whereas non-dynamic classes cannot. The Array class, for example, is dynamic since it needs to have all of the indexes added to it dynamically. If it was not dynamic, you would need to declare an infinite amount of properties in the class definition. Non-dynamic classes have all of there properties declared in the class definition and they are limited to those and only those properties. The Math class is not dynamic which means that you cannot add properties to it outside of the class definition (which is why the compiler gives you an error if you try to do just that). The best and most recommended solution is to extend the class and add your properties in there, or make it dynamic and add them from the class.

    See senocular's tutorial on OOP for more information:
    http://www.kirupa.com/developer/oop2...Structure7.htm
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  5. #20
    TheCanadian's Avatar
    10,305
    posts
    Noo doot aboot it, eh?
    Thanks for the comments, I'll write something about embedding fonts and why fonts are blurry at some point in the future
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  6. #21
    TheCanadian's Avatar
    10,305
    posts
    Noo doot aboot it, eh?

    How can I get the width of a loaded image?

    The Problem
    When loading an image into a movie clip, the width is never accurate:
    Code:
    this.createEmptyMovieClip("myMovieClip", 1);
    myMovieClip.loadMovie("myImage.png");
    trace(myMovieClip._width); //0
    The Answer
    This is pretty much the same deal as How come I can't use data from LoadVars or XML after I call load? The image hasn't loaded by the time your code has executed which means that your movie clip will be unchanged and thus have the same width as before you started the loading. The solution is a bit different with movie clips, however:

    You must have a continuous comparison of the bytes loaded into the movie and the total bytes of the image being loaded. When they are equal, the image has completely loaded and you can get the correct width:
    Code:
    this.createEmptyMovieClip("myMovieClip", 1);
    myMovieClip.loadMovie("myImage.png");
    myMovieClip.onEnterFrame = function():Void {
         if(this.getBytesLoaded() == this.getBytesTotal()) {
              trace(this._width); //width of loaded image
         }
    }
    More on how to do this correctly and an alternate approach (thanks scotty):
    http://www.kirupa.com/forum/showpost...5&postcount=22

    You can use the MovieClipLoader class, which does the process described above in its internal workings and has a lot of functionality for monitoring the progress of the download:
    Code:
    this.createEmptyMovieClip("myMovieClip", 1);
    imageLoader = new MovieClipLoader();
    imageLoaderListener = new Object();
     
    imageLoader.loadClip("myImage.png", myMovieClip);
    imageLoader.addListener(imageLoaderListener);
    imageLoaderListener.onLoadInit = function(targetMC:MovieClip):Void {
         trace(targetMC._width); //width of loaded image
    }
    Last edited by TheCanadian; August 27th, 2006 at 12:42 AM.
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  7. #22
    Two notes on the loadMovie.
    As soon as you load the picture in a movieclip, you can't use that movieclips onenterframe. The code will act like you've stated in the problem, it will perform the loadMovie command, but trace 0. Better is to create another mc and use that one's onenterframe to check if the picture is loaded.
    In theory, there's a moment that both bytesloaded and bytestotal are equal so it's better to check for bytesTotal as well. (Although it's not very likely this will happen on broadband connections)
    Code:
    var mc = this.createEmptyMovieClip("myMovieClip", 1);
    myMovieClip.loadMovie("myImage.png");
    var temp = this.createEmptyMovieClip("temp", 2);
    temp.onEnterFrame = function():Void  {
    	if (mc.getBytesLoaded() == mc.getBytesTotal() && mc.getBytesTotal()>0) {
    		trace(mc._width);
    		//width of loaded image
    		delete this.onEnterFrame;
    	}
    };
    Or you can check for the pictures width
    Code:
    var mc = this.createEmptyMovieClip("myMovieClip", 1);
    myMovieClip.loadMovie("myImage.png");
    var temp = this.createEmptyMovieClip("temp", 2);
    temp.onEnterFrame = function():Void  {
    	if (mc._width) {
    		trace(mc._width);
    		//width of loaded image
    		delete this.onEnterFrame;
    	}
    };
    scotty

  8. #23
    TheCanadian's Avatar
    10,305
    posts
    Noo doot aboot it, eh?
    Thanks for the additional information scotty, I added a link to your post in the answer
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  9. #24

  10. #25
    TheCanadian's Avatar
    10,305
    posts
    Noo doot aboot it, eh?

    What's the difference between function myFunction(){} and myFunction = function(){}?

    Although both are fundamentally the same there are some important differences. The declaration function myFunction(){} is called a named function. myFunction = function(){} is called an anonymous function and is basically a function literal referenced by a variable.

    1) Named functions are parsed before any other code being executed in the frame. That is, they can be called prior to their definition in the script. Anonymous functions cannot. For example, this will work:
    Code:
    //named function
    f(15); //15
    function f(x) {
     trace(x);
    }
    Whereas this will not:
    Code:
    //anonymous function
    f(15); //
    f = function(x) {
     trace(x);
    }
    2) Named functions cannot be defined within statement blocks (if, for, while, etc.) whereas anonymous functions can. For example, this will work:
    Code:
    //anonymous function
    if(true) {
     f = function(x) {
      trace(x);
     }
    }
    f(15); //15
    Whereas this will not:
    Code:
    //named function
    if(true) {
     function f(x) {
      trace(x);
     }
    }
    f(15); //
    3) Named functions cannot be used to declare the function in a scope other than the current scope. Since anonymous functions are just function literals assigned to a variable, they can be defined in the scope of any object in existence. For example, an anonymous function such as this:
    Code:
    //anonymous function
    myXML = new XML();
    myXML.onLoad = function() {}
    Is not possible with named functions.

    4) Named functions are used in AS2 class method and constructor declaration:
    Code:
    class MyClass {
     function MyClass(){}
     function classMethod(){}
    }
    Senocular also makes a good point about named functions and class methods in AS3:
    Quote Originally Posted by senocular
    for AS3 . . . scripts in timelines, named functions are methods [of the timeline's class] and anonymous functions are simply variables of the type Function


    off topic:
    -------------------------

    Whenever I try to write anonymous I subconsciously add an e at the end making it anonymouse. Every time! :fist:

    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  11. #26
    i have one tC. What are the benefits of using Void as return types and parameters? such as

    ActionScript Code:
    function onEnterFrame(Void):Void {




    vs

    ActionScript Code:
    function onEnterFrame() {



    always been a minor thing i never understood

  12. #27
    TheCanadian's Avatar
    10,305
    posts
    Noo doot aboot it, eh?

    What are advantages of strict data types for variables?

    In AS2:
    There is no advantage to the end user, data typing in AS2 is only for compiler error checking to help you code. This is because all variables are typed dynamically at run-time by the Flash Player.

    For example, if you try to assign a String object to a variable which is meant to reference a Number, you will get an error:
    Code:
    var n:Number;
    n = new String("hello"); //**Error** Type mismatch in assignment statement: found String where Number is required.
    If you didn't use strict data types for your variables, the compiler would assume everything is okay and you would be stuck wondering why the movie doesn't work the way it should:
    Code:
    var n;
    n = new String("hello"); //is fine according to the compiler
    n += 10; //expecting n to be a number
    trace(n); //will get hello10 when you expect some number
    The same applies to function return types since function returns are just references to objects in the memory which have types. If you assign the return of String.substring (which returns a String) to a variable with type Number, you will get an error the same way you got one above.

    Void return types follow the same story since they also indicate a type (or more correctly an absence) of data. If you were to try to assign the return of Array.reverse (for instance) to a strictly typed variable, you would get an error since the function has Void as it's return type (which, by definition, a variable cannot reference).

    In AS3:
    Strictly typed variables in AS3 will boost the performance of your movie since it will allow the virtual machine to know the types of your variables ahead of time.
    Quote Originally Posted by adobe
    In ActionScript 3.0, type information is preserved at runtime and utilized for a number of purposes. Flash Player performs runtime type checking, improving the system's type safety. Type information is also used to represent variables in native machine representations, improving performance and reducing memory usage.
    Last edited by TheCanadian; November 15th, 2006 at 07:06 PM.
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  13. #28
    TheCanadian's Avatar
    10,305
    posts
    Noo doot aboot it, eh?
    Quote Originally Posted by B L U E View Post
    i have one tC. What are the benefits of using Void as return types and parameters? such as

    ActionScript Code:

    function onEnterFrame(Void):Void {






    vs

    ActionScript Code:

    function onEnterFrame() {





    always been a minor thing i never understood
    Hopefully the above answers your question. Using Void as the parameter of a function is just a convention to indicate that there should be no arguments but is not checked by the compiler
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  14. #29
    TheCanadian's Avatar
    10,305
    posts
    Noo doot aboot it, eh?

    Can I change the frame rate of my movie?

    1) You can use setInterval to control the speed at which your timeline plays and/or as an alternative to onEnterFrame events.

    To adjust the speed at which the timeline plays, we can call a function which advances to the next frame:
    Code:
    this.stop();
    this.desriedFrameRate = 30;
    this.playRateInt = setInterval(this, "nextFrameSI", 1000 / this.desriedFrameRate);
    function nextFrameSI():Void {
     this.nextFrame();
     updateAfterEvent();
    }
    We must call updateAfterEvent if the desiredFrameRate is higher than the actual frame rate of your movie so that the stage will be redraw when you advance the frame (rather than on the movies regular interval).

    Since setInterval is used to call functions over an interval, it can be used as an alternative to onEnterFrame if you need it to run slower or faster:
    Code:
    this.desiredFrameRate = 5;
    this.callFunctionInt = setInterval(this, "otherOnEnterFrame", 1000 / this.desiredFrameRate);
    function otherOnEnterFrame():Void {
     trace("onEnterFrame");
    }
    Note that the above two methods do not actually change the frame rate of your movie, but rather allows you to control the rate at which the timeline plays and at which some functions are called.

    2) You can use streaming sound to directly change the frame of your main movie:
    Quote Originally Posted by senocular
    prior to AS3 you can also change the frame rate of the player by loading in a movie that has a streamed sound in it. The frame rate of that movie will then be used for your main movie (this has worked since at least Flash 5 if I remember right)
    See attached example.

    3) In AS3:
    This can be done very easily. Just set the Stage.frameRate property to your desired frame rate (between 0.01 and 1000).
    Attached Files Attached Files
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  15. #30
    TheCanadian's Avatar
    10,305
    posts
    Noo doot aboot it, eh?

    How can I use htmlText to call an ActionScript function?

    This is done using an anchor tag and the asfunction protocol. It looks something like this:

    asfunction:function:Function, parameter:String

    Note that the parameter is optional.

    The usage is fairly straight forward and there is a lot of information in the help files/LiveDocs but I'll go over some sample usages.

    The Basics
    Code:
    this.createTextField("myTextField", 1, 10, 10, 0, 0);
    this.myTextField.autoSize = true;
    this.myTextField.html = true;
    this.myTextField.htmlText = "<a href='asfunction:traceArgs,hello world!'>Press Me</a>";
    function traceArgs(a:String):Void {
           trace(a);
    }
    Whenever you press the text, Flash will output "hello world!"

    Passing Multiple Arguments
    The asfunction protocol only allows you to pass one argument to the function, but this can be easily remedied by using a character as a delimiter and splitting the string argument inside the function.
    Code:
    this.createTextField("myTextField", 1, 10, 10, 0, 0);
    this.myTextField.autoSize = true;
    this.myTextField.html = true;
    this.myTextField.htmlText = "<a href='asfunction:traceArgs,arg1, arg2, arg3, argN'>Press Me</a>";
    function traceArgs(a:String):Void {
     var args:Array = a.split(", ");
     for(var i:Number = 0; i < args.length; i++) {
      trace(args[i]);
     }
    }
    Now when you press the text, Flash will output each intended argument as an independant element of the args array.

    Calling Functions in Different Scopes
    To call a function in another scope, simply add the path to and the instance name of the movie clip before the function call - as in any other AS code:
    Code:
    this.myObject = new Object();
    this.myObject.method = function():Void {
     trace("called");
    }
    this.createTextField("myTextField", 1, 10, 10, 0, 0);
    this.myTextField.autoSize = true;
    this.myTextField.html = true;
    this.myTextField.htmlText = "<a href='asfunction:myObject.method'>Press Me</a>";
    Whenever you press the text, "called" is outputted.



    And that's about all there is to know to call AS functions from TextFields.
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

Page 2 of 4 FirstFirst 1234 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012