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

Flash CS6; AS3: How to load image from a link on one frame and addChild(image) on other?

Explorer ,
Jun 17, 2014 Jun 17, 2014

How can I addChild outside the frame of images loader function? When I try to addChild on the other frame of the same loader, I get an error.
I need to download all my 10 images only ONE TIME and place it on the screen in the other frames (to the same movie Clip).
Also I can only play this as3 coded frame once. I know how to add an array of images, but I only need to understand how to do it with one image.

Here is my loader for one image..


   var shirt1 = String("https://static.topsport.lt/sites/all/themes/topsport2/files/images/marskineliai_png/215.png");

   var img1Request:URLRequest = new URLRequest(shirt1);
  
var img1Loader:Loader = new Loader();
   img1Loader
.load(img1Request);
   myMovieClip
.removeChildAt(0);
   myMovieClip
.addChild(img1Loader);

TOPICS
ActionScript
2.4K
Translate
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

correct answers 1 Correct answer

LEGEND , Jun 17, 2014 Jun 17, 2014

You will need to declare the imgLoader outside of the function, otherwise it is limited in scope to within the function...


var img1Loader:Loader; 

function onLoaderComplete(e:Event):void
{

...
  img1Loader = new Loader();

Translate
LEGEND ,
Jun 17, 2014 Jun 17, 2014

What is the complete error message you get and what is the code you use on the other frame for the addChild ypou say doesn't work?

Translate
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, 2014 Jun 17, 2014
Symbol 'Spinner', Layer 'AS', Frame 2, Line 11120: Access of undefined property img1Loader.

[FRAME1]

import flash.display.Sprite;

import flash.events.Event;

import flash.net.URLLoader;

import flash.net.URLRequest;

import flash.events.*;

import flash.net.URLRequestHeader;

import flash.net.URLRequestMethod;

import flash.net.URLVariables;

import flash.events.SecurityErrorEvent;

function init(e:Event = null):void

{

    removeEventListener(Event.ADDED_TO_STAGE, init);

    var loader:URLLoader = new URLLoader();

    var request:URLRequest = new URLRequest("http://www.topsport.lt/front/Odds/affiliate/delfi");

  var acceptHeader:URLRequestHeader = new URLRequestHeader("Accept", "application/json");

  request.requestHeaders.push(acceptHeader);

  request.method = URLRequestMethod.POST;

    //request.url = _jsonPath;

    loader.addEventListener(Event.COMPLETE, onLoaderComplete);

  //loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

    loader.load(request);

  try {

                loader.load(request);

            } catch (error:Error) {

                trace("Unable to load requested document.");

            }

}

init();

function onLoaderComplete(e:Event):void

{

    var loader:URLLoader = URLLoader(e.target);

    var jsonObject:Object = JSON.parse(loader.data);

  var marsk1 = String("https://static.topsport.lt/sites/all/themes/topsport2/files/images/marskineliai_png/215.png");

  var img1Request:URLRequest = new URLRequest(marsk1);

  var img1Loader:Loader = new Loader();

  img1Loader.load(img1Request);

  _2.removeChildAt(0);

  if(_2 != null)

  _2.smoothing = true;

  //    the addChild which works when on frame one

  //_2.addChild(img1Loader);

}

[FRAME2]

  _2.addChild(img1Loader);

p.s. I removed the unnecessary code like other movieClips. It works then addChild function is on frame one.

I'm kind of new to as3. I started using it this month so sorry if it's the obvious mistake.
How to make flash recognize the loader?

Translate
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, 2014 Jun 17, 2014

You will need to declare the imgLoader outside of the function, otherwise it is limited in scope to within the function...


var img1Loader:Loader; 

function onLoaderComplete(e:Event):void
{

...
  img1Loader = new Loader();

Translate
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, 2014 Jun 17, 2014

It works!
I thank you from all my heart!
You just saved me from long-lasting desperation

Translate
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, 2014 Jun 17, 2014
LATEST

You're welcome

Translate
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