Jump to content
Search Community

accessing loaded swf's textfield and MC's

punchcreative test
Moderator Tag

Recommended Posts

i'm stuck on probably something simple to an advanced user

in a main class from wthin a function i call

var amsheet_loader:SWFLoader = new SWFLoader("./amSheet.swf", {name:"sheetAM", container:contentWindow, onProgress:progressHandler, onComplete:amSheetComplete});
amsheet_loader.load();

this is the listener object

	public function amSheetComplete(event:LoaderEvent):void {
		trace("amSheetComplete - " + contentWindow.getChildAt(0).name);
	}

this is wordking fine and i see the amSheet.swf is loaded in the contentWindow mc which is on the root timeline of main.swf ([sWF] Volumes:Media:Punch Sync MacBook:flash:app:swf:.:amSheet.swf - 590408 bytes after decompression)

in amSheet.swf there are some TLFTextFields on the stage, which i have given an embedded font, and a mc polaroid which holds a masked mc foto where i want to load a picture in.

in the amSheet class i have the folowing code which i thougt was going to fill the TLFTextFields and the fot mc in polaroid, but.....

public function AmSheet() {
		listSheetItems = new XMLList(Main.M._XML_sheet);
		var foto:ImageLoader = new ImageLoader("../am-img/" + Main.M._XML_sheet.@afb + ".png", {name:"sheetafb",container:this.polaroid.foto});
		createAMSheet(0);
	}
	private function createAMSheet(nr:Number):void {
		var sheetItems:XMLList = new XMLList(listSheetItems.children()[nr].children());
		//trace("de sheetItems 0 data uit XMLList: " + sheetItems);
		var teller:Number = sheetItems.length();
		var yPos:Number = 240;
		for (var i:Number = 0; i < teller;i++) {
			switch (sheetItems[i].@soort.toString()) {
				case  "kopregel":
					kop.text = sheetItems[i].text();
					trace(sheetItems[i].text());
					break;
				case  "tekst":
					this["t"+i].text = "•   " + sheetItems[i].text();
					trace(sheetItems[i].text());
					break;
				default:
					trace("niets gevonden!");
			}

		}

	}

when debugging i get this error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at nl.agis::AmSheet/createAMSheet()

at nl.agis::AmSheet()

Cannot display source code at this location.

Link to comment
Share on other sites

Sounds like that has nothing to do with LoaderMax - you've just got some code in your function that's resolving to a null reference somewhere. For example, maybe listSheetItems.children()[nr] doesn't exist, so when you try to get its children(), it throws the error. Or maybe listSheetItems doesn't exist yet when you call that or sheetItems is null. Try tracing those values to figure out which one is null.

Link to comment
Share on other sites

Attempting to launch and connect to Player using URL /Volumes/Media/Punch Sync MacBook/110202 Agis AMZM/flash/app/swf/main.swf

[sWF] Volumes:Media:Punch Sync MacBook:flash:app:swf:main.swf - 861006 bytes after decompression

fontName: Agis Klavika Medium

fontType: embeddedCFF

fontStyle: regular

fontName: Agis Klavika Medium

fontType: embeddedCFF

fontStyle: regular

1 steps: p91

XMLLoaderComplete: p01,p91

[sWF] Volumes:Media:Punch Sync MacBook:110202 Agis AMZM:flash:app:swf:.:amSheet.swf - 590626 bytes after decompression

listSheetItems traced:

Doorlopen eerste versie

inleiding

Fullscreen

Navigatie

invoer Accountmanager

Voordelen

Evaluatie

Afsluiting

sheetItems 0 data from XMLList:

sheetItems

Doorlopen eerste versie

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at nl.agis::AmSheet/createAMSheet()

at nl.agis::AmSheet()

Cannot display source code at this location.

 

this is the amSheet class

package  nl.agis {
import fl.text.TLFTextField;
import fl.transitions.*;
import fl.transitions.easing.*;
import flash.display.*;
import flash.events.*;
import flash.filters.*;
import flash.geom.*;
import flash.media.*;
import flash.net.*;
import flash.system.Security;
import flash.text.*;
import flash.text.Font;
import flash.ui.Keyboard;
import flash.utils.*;
import flashx.textLayout.container.*;
import flashx.textLayout.elements.*;
import flashx.textLayout.formats.*;
import com.greensock.*;
import com.greensock.TweenMax;
import com.greensock.easing.*;
import com.greensock.events.LoaderEvent;
import com.greensock.layout.*;
import com.greensock.loading.*;
import com.greensock.loading.display.*;
import flash.display.MovieClip;
import Main;

public class AmSheet extends MovieClip {
	public var kop:TLFTextField;
	public var t1:TLFTextField;
	public var t2:TLFTextField;
	public var t3:TLFTextField;
	public var t4:TLFTextField;
	public var t5:TLFTextField;
	public var t6:TLFTextField;
	public var t7:TLFTextField;
	public var sub:TLFTextField;
	public var listSheetItems:XMLList;

	public function AmSheet() {
		listSheetItems = new XMLList(Main.M._XML_sheet);
		trace("listSheetItems traced:");
		trace(listSheetItems);
		var foto:ImageLoader = new ImageLoader("../am-img/" + Main.M._XML_sheet.@afb + ".png", {name:"sheetafb",container:this.polaroid.foto});
		createAMSheet(0);
	}
	private function createAMSheet(nr:Number):void {
		var sheetItems:XMLList = new XMLList(listSheetItems.children()[nr].children());
		trace("sheetItems 0 data from XMLList:");
		trace("sheetItems");
		var teller:Number = sheetItems.length();
		var yPos:Number = 240;
		for (var i:Number = 0; i < teller;i++) {
			switch (sheetItems[i].@soort.toString()) {
				case  "kopregel":
					trace(sheetItems[i].text());
					kop.text = sheetItems[i].text();
					break;
				case  "tekst":
					trace(sheetItems[i].text());
					this["t"+i].text = "•   " + sheetItems[i].text();
					break;
				default:
					trace("niets gevonden!");
			}

		}

	}

}

}

seems like i'm doing this wrong

var sheetItems:XMLList = new XMLList(listSheetItems.children()[nr].children());

i'm a bit blacked out at the moment

Link to comment
Share on other sites

as the SWFLoader loads the amSheet.swf correctly

how can i access the loaded swf's TLFTextfields and mc from the main class (root)

i tried contentWindow.sheetAM.kop.text as sheetAm is the name i gave the loaded SWF in the amSheetComplete function

 

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at nl.agis::AmSheet/createAMSheet()
at nl.agis::AmSheet()
Cannot display source code at this location.

 

by the way, replying on a saturday is really a BIG UP :D

deadline is chasing me

Link to comment
Share on other sites

Yeah, it looks like you're not targeting the XML properly. I think you're probably trying to do this:

 

var sheetItems:XMLList = listSheetItems.params[0].sheet[0].item;

 

Here's a great article from Senocular that might help:

http://www.senocular.com/flash/tutorial ... page=4#e4x

 

As far as targeting the swf's content, you wouldn't use contentWindow.sheetAm because the SWFLoader always loads the raw content into a ContentDisplay Sprite - that Sprite is what gets put into your container. So your code would look more like:

 

amsheet_loader.rawContent.sheetAm

 

rawContent refers to the...raw content (you'd never guess, I know). That's typically the root of your subloaded swf.

Link to comment
Share on other sites

i'm on my way of getting there

even targetting the loaded SWF from Main succeeds

from within the complete function i used

event.target.rawContent.kop.text = "just a test";

 

to solve an issue on the loaded AMSheet i skipped TLFTexField and used the classic version

 

the XML tut came in very handy

 

thanx sofar (guess i'll be back)

Link to comment
Share on other sites

still have a problem to access content in a loader on the stage

this time i want a netstream to be closed

in the main class i use a xmlloaded listener to select a proper loader for the upcoming content

public function XMLLoaderComplete(event:LoaderEvent):void {
		_XML_sheet = XML(LoaderMax.getContent("sheetData"));
		appSteps[2] = _XML_sheet.@label;
		if (_XML_sheet.@nextSheet != "") {
			appSteps[1] = _XML_sheet.@nextSheet;
			contentWindow.addEventListener(MouseEvent.CLICK, nextStepClick, false, 0, true);
		} else {
			appSteps[1] = "";
			navBalk.fwd.enabled = false;
			navBalk.fwd.removeEventListener(MouseEvent.CLICK, nextStepClick);
		}
		if (appStepBack.length == 0) {
			navBalk.back.enabled = false;
			navBalk.back.removeEventListener(MouseEvent.CLICK, backStep);
		} else {
			navBalk.back.enabled = true;
			navBalk.back.addEventListener(MouseEvent.CLICK, backStep, false, 0, true);
			navBalk.fwd.addEventListener(MouseEvent.CLICK, nextStepClick, false, 0, true);
		}
		//trace("terug = " + appSteps[0], "huidig = " + appSteps[2],"volgende = " + appSteps[1],"back = " + appStepBack);

		initHeader(_XML_sheet.@headerfoto,_XML_sheet.@titel,_XML_sheet.@headernav,_XML_sheet.@headerkleur);

		if  (_XML_sheet.@item.toString() == "img") {
			imgloader = new ImageLoader(debugging + "sheets/" + _XML_sheet.@label + ".png", {name:"sheetImage",alpha:1,container:contentWindow,onError:mQerrorHandler, onProgress:progressHandler, onComplete:sheetComplete});
			imgloader.load();
		} else if (_XML_sheet.@item.toString() == "menusheet" || _XML_sheet.@item.toString() == "amsheet" || _XML_sheet.@item.toString() == "swf" || _XML_sheet.@item.toString() == "vid") {

			switch (_XML_sheet.@item.toString()) {
				case "amsheet":
					swfloader = new SWFLoader(debugging + "swf/amSheet.swf", {name:"amSWF",alpha:1, container:contentWindow,onError:mQerrorHandler, onProgress:progressHandler, onComplete:sheetComplete});
					swfloader.load();
					break;
				case "menusheet":
					swfloader = new SWFLoader(debugging + "swf/" + _XML_sheet.@label + ".swf", {name:"menuSWF",alpha:1,container:contentWindow,onError:mQerrorHandler, onProgress:progressHandler, onComplete:sheetComplete});
					swfloader.load();
					break;
				case "swf":
					swfloader = new SWFLoader(debugging + "swf/" + _XML_sheet.@label + ".swf", {name:"sheetSWF",alpha:1, container:contentWindow,onError:mQerrorHandler, onProgress:progressHandler, onComplete:sheetComplete});
					swfloader.load();
					break;
				case "vid":
					swfloader = new SWFLoader(debugging + "swf/video.swf", {name:"vidSWF",alpha:1, container:contentWindow,onError:mQerrorHandler, onProgress:progressHandler, onComplete:sheetComplete});
					swfloader.load();
					break;
				default:
					header.titel.text = "Sheet niet gevonden";
			}
		}

	}

then when i have the case "vid", a loader is doing it's job fine and loads the video which nicely starts playing

here's the code in the video.swf which is loaded from main class

video = new VideoLoader(Main.M.debugging + videoFile, {name:"vid",prependURLs:Main.M.debugging , container:this.vidPlayer.vidMC, width:600, height:338, scaleMode:"none", bgColor:0xFFFFFF, autoPlay:true, volume:0.8, requireWithRoot:this.root, estimatedBytes:17500000});
		video.load();

when i try to close the netstream on the video loader from my main class (it's a key or mouseEvent which triggers this) i get an error

here's the code in the main class which i hoped would stop the netstream

public function clearContentMC(mc:MovieClip):void {
		if (geladenSheet == "vidSWF") {
			trace("geladen sheet is video");
			swfloader.rawContent.video.netStream.close();
		}
		trace("in initLoader clearContent functie children = " + mc.numChildren, mc.getChildAt(0), mc.root.name );
		while (mc.numChildren > 0) {
			mc.removeChildAt(0);
		}
		stage.focus=stage;
	}

and here's the debuggers thoughts on it:

geladen sheet is video
ReferenceError: Error #1069: Property video not found on nl.agis.Video and there is no default value.
at Main/clearContentMC()[/Volumes/Media/Punch Sync MacBook/110202 Agis AMZM/flash/fla/Main.as]
at Main/initLoader()[/Volumes/Media/Punch Sync MacBook/110202 Agis AMZM/flash/fla/Main.as]
at Main/nextStep()[/Volumes/Media/Punch Sync MacBook/110202 Agis AMZM/flash/fla/Main.as]
at Main/keyPressedDown()[/Volumes/Media/Punch Sync MacBook/110202 Agis AMZM/flash/fla/Main.as]
Debug session terminated.

to be honest i don't know how to destroy all currently loaded content in the contentWindow mc on the main timeline and cleanup properly

i discovered that things were left behind because the video keeps playing even if the contentWindow is loaded with new content

and accessing the content which is put in mc contentWindow by the chosen loader on the main class seems difficult to me

 

here's what i've tried sofar

swfloader.rawContent.video.content.vidPlayer.vidMC.netStream.close();

swfloader.rawContent.video.content.netStream.close();

swfloader.rawContent.video.rawContent.netStream.close();

swfloader.content.video.rawContent.netStream.close();

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...