• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

how do i load a sequence of numbered images using AS3.0?

Explorer ,
Jun 16, 2012 Jun 16, 2012

Copy link to clipboard

Copied

To avoid importing loads of images into a Flash file and putting them on the timeline, i should like to simulate a movie clip by using an image-sequence, that is, by sequentially loading a series of still images, to& then, to "activate" - or view the sequence upon mouse-click, .

i figure this involves a loop and array, but i can't figure out the code.

Plz help.

thanks.

TOPICS
ActionScript

Views

3.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 16, 2012 Jun 16, 2012

Copy link to clipboard

Copied

To sequentially load anything you need to use a functional loop (and the array and a counter variable).  The basics of it are outlined below, but not in actual coding syntax, mainly descriptive...

var array:Array = new Array(your array of images); (if these are numerically named, then you may not need the array, just a count value so you know when to stop)

var count:int = 0;

function loadCurrentI mage(){

     loader.load(array[count])

     loader.contentLoaderInfo.addEventListener(COMPLETE,loadComplete)

}

function loadComplete(evt...){

     // first process loaded image, then...

    count++;

    if(count < array.length){

        loadCurrent();  // load the next image

    } else {

        // sequencial loading complete, carry on to next activity

    }

       

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 16, 2012 Jun 16, 2012

Copy link to clipboard

Copied

hi Ned. Have built it up to proper syntax but getting an error:

Scene 1, Layer 'Layer 1', Frame 1, Line 51067: Implicit coercion of a value of type Array to an unrelated type String.

This happens when the jpg images are in the same directory as the FLA file.

On the other hand, when the images are in a folder on their own, also in the same file as the FLA file, using the path in AS URL request (var req:URLRequest = new URLRequest("../twirl_test"+imageArray); i get a security error that i've experienced in the past as relating to improper path: SecurityError: Error #2000: No active security context.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 16, 2012 Jun 16, 2012

Copy link to clipboard

Copied

I can't help with the 1067 error without seeing the code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 16, 2012 Jun 16, 2012

Copy link to clipboard

Copied

import flash.net.URLRequest;

import flash.display.Loader;

import flash.events.Event;

var count:int = 0;

var imageArray:Array=["image1.jpg","image2.jpg","image3.jpg","image4.jpg","image5.jpg","image6.jpg","image7.jpg",

"image8.jpg","image9.jpg","image10.jpg"];

var url:String = "D:/flash cs5.5/image_sequence/twirl_test/"+imageArray;//TypeError: Error #2007: Parameter url must be non-null.

//var req:URLRequest = new URLRequest("../twirl_test/"+imageArray);

var request:URLRequest = new URLRequest(url);//SecurityError: Error #2000: No active security context.

var loader:Loader = new Loader();

//this is if u dont want the loader on the stage BETTER PRACTICE

function imageLoaded(event:Event):void

{

    addChild(loader);

}

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);

loader.load(request);

function loadCurrentImage(){

     loader.load(imageArray[count])

     loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete)

}

function loadComplete(event:Event){

     // first process loaded image, then...

    count++;

    if(count < imageArray.length){

        loadCurrentImage();  // load the next image

    } else {

        // sequencial loading complete, carry on to next activity

    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 16, 2012 Jun 16, 2012

Copy link to clipboard

Copied

var url:String = "D:/flash cs5.5/image_sequence/twirl_test/"+imageArray;

That array being added to the end isn't going to do much for you.  I am guess you really just wanted one element of the array, not the array itself.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 17, 2012 Jun 17, 2012

Copy link to clipboard

Copied

one element added at a time.

any help, from anyone, would be appreciated.

Ned, i am wondering if this - adding images sequentially to have a moving-image effect may be done using indexing - by adding one image to one loader on one frame? if so, can u help with the code for index? i cant remember how it's done. thanks for your help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 17, 2012 Jun 17, 2012

Copy link to clipboard

Copied

If you only want one element, then only specify one element.  Using "imageArray" like you show is attempting to assign an array to a string.  One element involves specifying an index value... imageArray[index]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 17, 2012 Jun 17, 2012

Copy link to clipboard

Copied

Ned, sorry, this is too cryptic for me to follow, i suppose i need to see examples of code to know what u mean.

thanks anyway.

best.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 17, 2012 Jun 17, 2012

Copy link to clipboard

Copied

YOu've already provided the example, you just need to realize what you have written versus what you want to write.

var url:String = "D:/flash cs5.5/image_sequence/twirl_test/"+imageArray;

What do you imagine that "imageArray" is doing at the end of your line of code there?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 17, 2012 Jun 17, 2012

Copy link to clipboard

Copied

i imagine that once the path is established (the string), imageArray is the variable specified for it. The array - imageArray, is, i am imagining, the still images inside the folder thats in the url string, and therefor, in adding imageArray, it's like referring to the group of images versus one specific image, as such "D:/flash cs5.5/image_sequence/twirl_test/image1.jpg

so instead of getting image1.jpg, i am trying to tell Flash to get the images in the array, in accordance with their numeric order.

that's what i imagine.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 17, 2012 Jun 17, 2012

Copy link to clipboard

Copied

If that is what you think you want to do, then that is the problem.  You only want to ask for one image at a time.  By appending the entire array to the url, your attempting to add apples (an array) to oranges (a string)... they are two different classes of objects.  You want to add strings to strings... and your array contains individual strings.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 18, 2012 Jun 18, 2012

Copy link to clipboard

Copied

LATEST

Ned. i simply do not know how to load a sequential array of images, so if you know how to and would like to share the code. Please do.

thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines