Macromedia Flash Professional 8.0 Full Version for PC, Mac (PFD080D000) Logo
Posted on Apr 15, 2009
Answered by a Fixya Expert

Trustworthy Expert Solutions

At Fixya.com, our trusted experts are meticulously vetted and possess extensive experience in their respective fields. Backed by a community of knowledgeable professionals, our platform ensures that the solutions provided are thoroughly researched and validated.

View Our Top Experts

How to define variables in flash action script for every movie that i want

1 Answer

Anonymous

Level 2:

An expert who has achieved level 2 by getting 100 points

MVP:

An expert that got 5 achievements.

Vice President:

An expert whose answer got voted for 100 times.

Champion:

An expert who has answered 200 questions.

  • Expert 205 Answers
  • Posted on Apr 15, 2009
Anonymous
Expert
Level 2:

An expert who has achieved level 2 by getting 100 points

MVP:

An expert that got 5 achievements.

Vice President:

An expert whose answer got voted for 100 times.

Champion:

An expert who has answered 200 questions.

Joined: Apr 08, 2009
Answers
205
Questions
0
Helped
99885
Points
460

Using variables in a project

When you build animations or applications with Flash, there are very few situations in which you don't need to use any kind of variable in your project. For example, if you build a login system, you might need variables to determine whether the user name and password are valid, or whether they are filled in at all.

You can find more information on loading variables (such as name/value pairs) in Working with External Data.

In the following example, you use variables to store the path of an image you are loading with the Loader class, a variable for the instance of the Loader class, and a couple of functions that are called depending on whether the file is successfully loaded or not.
To use variables in a project:

1. Create a new Flash document, and save it as imgloader.fla.
2. Select Frame 1 of the Timeline, and add the following ActionScript to the Actions panel:

/* Specify default image in case there wasn't a value passed using FlashVars. */
var imgUrl:String = "http://www.helpexamples.com/flash/images/image1.jpg";
if (_level0.imgURL != undefined) {
// If image was specified, overwrite default value.
imgUrl = _level0.imgURL;
}

  • 1 more comment 
  • Anonymous Apr 15, 2009


    this.createEmptyMovieClip("img_mc", 10);
    var mclListener:Object = new Object();
    mclListener.onLoadInit = function(target_mc:MovieClip):Void {
    target_mc._x = (Stage.width - target_mc._width) / 2;
    target_mc._y = (Stage.height - target_mc._height) / 2;
    }
    mclListener.onLoadError = function(target_mc:MovieClip):Void {
    target_mc.createTextField("error_txt", 1, 0, 0, 100, 20);
    target_mc.error_txt.autoSize = "left";
    target_mc.error_txt.text = "Error downloading specified image;\n\t" + target_mc._url;
    }
    var myMCL:MovieClipLoader = new MovieClipLoader();
    myMCL.addListener(mclListener);
    myMCL.loadClip(imgUrl, img_mc);

    The first line of code specifies the image that you want to dynamically load into your Flash document. Next, you check whether a new value for imgURL was specified using FlashVars or URL-encoded variables. If a new value was specified, the default image URL is overwritten with the new value. For information on using URL variables, see Using variables from the URL. For information on FlashVars, see Using FlashVars in an application.

    The next couple of lines of code define the MovieClip instance, and a Listener object for the future MovieClipLoader instance. The MovieClipLoader's Listener object defines two event handlers, onLoadInit and onLoadError. The handlers are invoked when the image successfully loads and initializes on the Stage, or if the image fails to load. Then you create a MovieClipLoader instance, and use the addListener() method to add the previously defined listener object to the MovieClipLoader. Finally, the image is downloaded and triggered when you call the MovieClipLoader.loadClip() method, which specifies the image file to load and the target movie clip to load the image into.
    3. Select Control > Test Movie to test the document.

  • Anonymous Apr 15, 2009


    Because you're testing the Flash document in the authoring tool, no value for imgUrl will be passed by FlashVars or along the URL, and therefore the default image displays.
    4. Save the Flash document and select File > Publish to publish the file as a SWF and HTML document.

    NOTE





    Make sure that Flash and HTML are both selected in the Publish Settings dialog box. Select File > Publish Settings and then click the Formats tab. Then, select both options.
    5. If you test your document in the Flash tool (select Control > Test Movie) or in a local browser (File > Publish Preview > HTML), you will see that the image centers itself both vertically and horizontally on the Stage.
    6. Edit the generated HTML document in an editor (such as Dreamweaver or Notepad), and modify the default HTML to match the following text:




    http://www.helpexamples.com/flash/images...">


    http://www.helpexamples.com/flash/images..." bgcolor="#ffffff" width="550" height="400" name="urlvariables" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />


    7. Test the HTML document to see the changes. An image that you specify in the HTML code appears in the SWF file.

    To modify this example to use your own images, you would modify the FlashVars value (the string inside the double quotes).

  • Anonymous Apr 15, 2009

    Let me know if this what you are looking for

×

Add Your Answer

×

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

1,259 views

Ask a Question

Usually answered in minutes!

Top Macromedia Computers & Internet Experts

Brad Brown

Level 3 Expert

19190 Answers

Rob Hill
Rob Hill

Level 3 Expert

1483 Answers

ADMIN Eric
ADMIN Eric

Level 3 Expert

42247 Answers

Are you a Macromedia Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...